In the first part of setting up Ansible
with PIP we have installed Ansible
on Ubuntu 20.04
LTS that is our Control
Node, if you don't have Ansible
installed on Control node than refer
How to install Ansible
with PIP in Ubuntu.
This tutorial will walk through the steps for setting up Control Node, Managed Node and testing connection between Control Node and Managed Node.
ansible
user on Managed NodeAnsible
runs command as ansible user
on managed node, so we need ansible user created on all managed nodes.
Run below command for creating ansible user
, note down the password and IP as these details would be required in setting up control node.
[email protected]:~$ sudo adduser ansible
Control Node
for running ad-hoc
commandsTill now we have Ansible
running on Control Node and ansible
user created on Managed Node. We need to perform below steps
to complete the set up on Control Node.
Managed Node
in /etc/hosts
of Control node
[email protected]:~$ sudo vi /etc/hosts
Add below entry in /etc/hosts
, replace [IP] with IP of your Managed Node and save the configuration.
[IP] managed-node-1
Ansible
project directory on Control Node
[email protected]:~$ cd /home/ansible;
[email protected]:~$ mkdir test-ansible;
[email protected]:~$ cd test-ansible;
ansible.cfg
generated, we will create
it manually inside Ansible project directory that is test-ansible
[email protected]:~$ vi /home/ansible/test-ansible/ansible.cfg
Write below lines in ansible.cfg
[defaults]
inventory=./inventory
managed-node-1
[email protected]:~$ vi /home/ansible/test-ansible/hosts
Write below line in hosts
managed-node-1
Control node
with default values
[email protected]:~$ ssh-keygen
managed-node-1
, this will prompt for password provided for ansible user on Managed Node
[email protected]:~$ ssh-copy-id -i ~/.ssh/id_rsa [email protected]
With these steps set up for both Control and Managed node is complete, lets verify connection with ping
.
List all hosts in inventory
[email protected]:~$ ansible all -i hosts --list-hosts
Output
hosts (1):
managed-node-1
Execute ping command for all Managed Nodes
, in this case we have only one node managed-node-1
[email protected]:~$ ansible -i hosts -m ping all
You should see output for managed nodes similar to the below one
managed-node-1 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
If you are getting any error while following this tutorial, please post errors in comments, we will try to resolve those as soon as possible.
Ansible Installation < Prev Next >Managing Apache with AnsibleCategories: Linux
Similar Articles