Ansible - How to setup Ansible Environment
In my example, I will should you how to setup your ansible environment and run the ping module.
1) I have created 3 Ubuntu servers with the names:-
Server1 - Installed Ansible
Server2 - Client Node1
Server3- Client Node2
Note:- I installed ansible on Server1 by running the below commands on ubuntu:-
sudo apt-add-repository ppa:ansible/ansible
sudo apt update
sudo apt install ansible
Once ansible is installed on the server1, we can check it by running the command:- ansible --version
2) Then I generated ssh-keys on the server1 by running the command:= ssh-keygen -t rsa
3) Then I copied the keygen to all servers by running the command:- ssh-copy-id <IP Address>
For Example:-
ssh-copy-id 192.168.181.11
ssh-copy-id 192.168.181.12
ssh-copy-id 192.168.181.13
Server1
Server2
This is to make sure, we can run the ansible playbooks from the ansible server. I will be using root user to execute the playbooks.
4) Then I created a folder scripts which will be used for keeping all my playbooks, inventory files etc.
5) Then I created my inventory file in the same folder as inv
The all group is having all the 3 hosts - server1, server2 and server3 and the app group is having 2 hosts:- server2 and server3 as shown below
6) I also created a file ansible.cfg in the same folder - scripts and defined the name of my inventory file.
In my example, it is inv
Command:- ansible -m ping [Name of the group defined in inventory file - inv)
In my example, I am running it on app group
The above screenshots refers successfully connectivity between all the servers from the ansible server -server1.
No comments:
Post a Comment