Ansible connect Linux node

Ansible is an IT automation tool intended to facilitate the management of remote servers. Ansible requires Python (version 2.7 or 3.5 and higher) to run. Ansible is run from a centralized control node and can manage any server accessible over SSH. 

INSTALLATION OF ANSIBLE IN CENTOS
To explore Ansible as a way to manage various servers, you need to install Ansible software on at least one computer.
To get the Ansible of CentOS 7, first, make sure that the CentOS 7 epel repository is installed.
#sudo yum install epel-release -y

After installation, use the yum repository to install Ansible.
#sudo yum install ansible -y

We have all the software you need to manage your server using Ansible. Now we can check the ansible directory,
# cd /etc/ansible/

If ansible installed means check directories & files,
# ls

You will see the default directory & host files,
# ansible.cfg hosts roles

Create a User for Ansible Controller and Managed Node.
#useradd admin
#passwd admin

Configure the Control Node User for Passwordless Super User Access
On the managed node, we need to ensure our Ansible user can utilize the sudo command without a password. Run the following command to open the sudoers file for editing.
# visudo
Type ‘i’ to enter input mode and add the following to the end of the file.
admin ALL=(ALL) NOPASSWD: ALL

Configure our Admin User for SSH Access
We need to ensure our admin user can access the managed node over SSH without a password. We will set up an SSH key pair to allow this
# ssh-keygen

Now we have to copy the public key to our managed node with the following command.
# ssh-copy-id [email protected]

Create an Ansible Inventory
Ansible requires an inventory list so it can identify your managed nodes. To add our managed node to the inventory, we need to log in to our Control node as the admin user. create an inventory file.
#vi /home/admin/inventory
Type ‘i’ to enter insert mode and add the managed node details to the inventory file
# cat inventory
[node]
192.168.1.4
Now we are going to issue a ping command from the Ansible Control node to ensure that they are reachable.
# ansible all -i inventory -m ping
192.168.1.4 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": false,
"ping": "pong"
}

From the output above, we can clearly see that the ping command was successful and we were able to test the reachability of the node.




Recent Comments

No comments

Leave a Comment