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.
[[email protected] ~]# rpm -iUvhhttp://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
Step two: use yum to install Ansible
[[email protected] ~]# yum installansible
After the installation is complete, check the Ansible version:
[[email protected] ~]# ansible–version
Step three: set up SSH for node authentication key
Ansible server generated key and copy the public key to the node.
[email protected] ~]# 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.
[[email protected] ~]# vi/etc/ansible/hosts
Save and exit the file.
Fifth step: try Ansible server run the command
Use ping to check ‘Test-servers’ or Ansible node connectivity.
[[email protected] ~]# ansible -mping ‘test-servers’
Execute shell command
1: check the running time for the Ansible (uptime)
[[email protected] ~]# ansible -mcommand -a “uptime” ‘test-servers’
2: check the node the kernel version
[[email protected] ~]# ansible -mcommand -a “uname -r” ‘test-servers’
3: for a node to increase user
[[email protected] ~]# ansible -mcommand -a “useradd mark” ‘test-servers’
[[email protected] ~]# ansible -mcommand -a “grep mark /etc/passwd” ‘test-servers’
4: to redirect the output to a file
[[email protected] ~]# 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