Ansible is a type of Unix system development of free and open source configuration and automation tools. It is written in Python, similar to the Chef or Puppet, but there‘s a difference and advantage is that we do not need to install any client node. It uses SSH to communicate with node.
In this article we will install and configure the Ansible on the CentOS7 and trying to manage two nodes.
Ansible Server – Ansible.linuxtechi.com (192.168.1.15)
Node – 192.168.1.9, 192.168.1.10
First step: set the EPEL repository
Ansible warehouse is not in the yum repository by default, so we need to use the following command to enable EPEL repository.
[root@ansible ~]# rpm -iUvhhttp://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
Step two: use yum to install Ansible
[root@ansible ~]# yum installansible
After the installation is complete, check the Ansible version:
[root@ansible ~]# ansible–version
Step three: set up SSH for node authentication key
Ansible server generated key and copy the public key to the node.
root@ansible ~]# ssh-keygen
Use the SSH-copy-ID command to copy the Ansible public key to a node.
Fourth step: defining nodes for Ansible listing
The list of file servers in the/etc/Ansible/hosts maintains the Ansible.
[root@ansible ~]# vi/etc/ansible/hosts
[test-servers]
192.168.1.9
192.168.1.10
Save and exit the file.
Fifth step: try Ansible server run the command
Use ping to check ‘Test-servers’ or Ansible node connectivity.
[root@ansible ~]# ansible -mping ‘test-servers’
Execute shell command
1: check the running time for the Ansible (uptime)
[root@ansible ~]# ansible -mcommand -a “uptime” ‘test-servers’
2: check the node the kernel version
[root@ansible ~]# ansible -mcommand -a “uname -r” ‘test-servers’
3: for a node to increase user
[root@ansible ~]# ansible -mcommand -a “useradd mark” ‘test-servers’
[root@ansible ~]# ansible -mcommand -a “grep mark /etc/passwd” ‘test-servers’
4: to redirect the output to a file
[root@ansible ~]# ansible -mcommand -a “df -Th” ‘test-servers’ > /tmp/command-output.txt
Free brothers original Linux operations engineer video/elaborate on IT education Linux tutorials, consult the official website customer service for details: http://www.lampbrother.NET/Linux/
Or seduce Q2430675018
Welcome to the Linux Exchange Group 478068715