ANSIBLE
We are introducing in our blog ANSIBLE in order to help to the community.
Create a Inventory File with the server list called "TEST"
$cat inventory
[TEST]
server1
server2
server3
server4
server5
And now we can use our ansible scripts
ANSIBLE COPY A FILE TO SERVERS LIST IN THE INVENTORY
---
- name: upload a file to server list
hosts: TEST
tasks:
- name: copy a file
copy -a "src=/home/user1/ansible/p25739822_81617613_SOLARIS64.zip dest=/tmp"
ANSIBLE COPY A FILE AND UNCOMPRESS A FILE
---
- name: upload a file to a server list a uncompress the file
hosts: server1 server3 server4 <----- You can use the server list with spaces
tasks:
- name: cambia directorio y descomprime
unarchive: src=/tmp/p25739822_81617613_SOLARIS64.zip dest=/tmp/ copy=no
ANSIBLE CHANGE A LINE IN FILE (IN THIS CASE /etc/hosts file)
---
- name: modify line
hosts: TEST
tasks:
- name: Replace the line in the regular expresion
lineinfile:
path: /etc/hosts
regexp: '^190.167.1.20'
line: '190.167.1.20 gray.example.com gray'
ANSIBLE REDIRECT OUTPUT
Previously we have created a list of scripts (ls.sh and passwd.sh) in order to run those command in a list of server
---
- name: Auditory File
hosts: TEST
tasks:
- name: ls command
script: ls.sh
register: out
- debug: var=out.stdout_lines
- name: cat passwd
script: passwd.sh
register: out
- debug: var=out.stdout_lines
ANSIBLE AVOID ROOT LOGIN RESTART SSH SERVICES AND CHECKING IT
---
- name: edit /etc/ssh/sshd_config to avoid root login
hosts: TEST
tasks:
- name: Modify /etc/ssh/sshd_config, line PermitRootLogin
lineinfile:
path: /etc/ssh/sshd_config
regexp: 'PermitRootLogin'
line: 'PermitRootLogin no'
- name: restart sshd daemon
command: sudo /usr/sbin/svcadm restart ssh
ignore_errors: yes
- name: status sshd daemon
command: sudo /usr/bin/svcs ssh
ignore_errors: yes
We will post more information sooner
Regards
Roger
Comments