|
Ansible is a Unix-like system for the development of free and open source configuration and automation tools. It is written in Python, like Chef and Puppet, but there is a distinct advantage and we do not need to install any client in the node. It uses SSH and nodes to communicate.
This blog entry we will install and configure on a CentOS 7 Ansible, and try to manage two nodes.
Ansible server - ansible.linuxtechi.com (192.168.1.15)
Node - 192.168.1.9, 192.168.1.10
Step 1: Set EPEL repository
Ansible warehouse default yum repository is not, so we need to use the following command to enable epel warehouse.
[Root @ ansible ~] # rpm -iUvh http://dl.Fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
Step 2: Use yum install Ansible
[Root @ ansible ~] #yum install ansible
After the installation is complete, check ansible Version:
[Root @ ansible ~] # ansible --version
ansible-version
Step 3: Set SSH keys for authentication node
Generate key Ansible server and copy the public key to the node.
root @ ansible ~] # ssh-keygen
ssh-keygen
Use ssh-copy-id command to copy the public key to Ansible node.
ssh-copy-id-command
STEP 4: Ansible defined node list
File / etc / ansible / hosts Ansible maintains a list of servers.
[Root @ ansible ~] # vi / etc / ansible / hosts
[Test-servers]
192.168.1.9
192.168.1.10
Save and exit the file.
Hosts file examples below
nsible-host
Step five: Try to run the server command Ansible
Use ping to check connectivity 'test-servers' or ansible node.
[Root @ ansible ~] # ansible -m ping'test-servers'
ansible-ping
Execute shell commands
Run time check Ansible node (uptime): Example 1
[Root @ ansible ~] # ansible -m command -a "uptime" 'test-servers'
ansible-uptime
Kernel version check node: Example 2
[Root @ ansible ~] # ansible -m command -a "uname -r" 'test-servers'
kernel-version-ansible
Example 3: to increase the user node
[Root @ ansible ~] # ansible -m command -a "useradd mark" 'test-servers'
[Root @ ansible ~] # ansible -m command -a "grep mark / etc / passwd" 'test-servers'
useradd-ansible
Example 4: redirect the output to a file
[Root @ ansible ~] # ansible -m command -a "df -Th" 'test-servers'> / tmp / command-output.txt
redirecting-output-ansible |
|
|
|