Launch 2 Hosts and Set-Up in Inventory File

Share via:

Dear Readers,

In this article,we will see Launch 2 Hosts and Set-Up in Inventory File.

What is Inventory file?

  • Ansible works against multiple managed hosts in your infrastructure at the same time, using a list or group of lists         is known as the inventory.
  • The Ansible inventory file defines the hosts and groups of hosts upon which commands, modules, and tasks in a           playbook operate.
  • The file can be in one of many formats depending on your Ansible environment and plugins.
  • The default location for the inventory file is /etc/ansible/hosts.If necessary, you can also create project-specific              inventory files in alternate locations.
  • The inventory file can list individual hosts or user-defined groups of hosts.

Steps to Follow

  1. Launch 2 Hosts “Ansible-Node-1” and “Ansible-Node-2”.
  2. Create a group and mention Hosts Private IP under the group in the Inventory file “/etc/ansible/hosts”.
  3. Uncomment two files “inventory = /etc/ansible/hosts” and “sudo_user = root” in the ansible configuration file “/etc/ansible/ansible.cfg”.

1. Launch 2 Hosts “Ansible-Node-1” and “Ansible-Node-2”

Check Availability Zone of your Ansible Machine

we can see the Availability Zone “ap-south-1b” of your Ansible machine.

Note

Ansible machine is in ap-south-1b AZ.
we create 2 nodes at the same time by selecting 2 instances in the same Availability Zone “ap-south-1b”.
we need to open SSH and HTTP ports.

Create 2 Nodes “Ansible-Node-1” and “Ansible-Node-2”

Launch Linux EC2 Instance

Check below link to Launch Linux EC2 Instance.

Launch Linux EC2 Instance

We can see the 2 nodes  “Ansible-Node-1”  and “Ansible-Node-” which was created earlier.

Whenever we install ansible By default ,we will get two files “ansible.cfg”  and “hosts” in the /etc/ansible” directory.

2. Create a group and mention Hosts Private IP under the group in the Inventory file “/etc/ansible/hosts”

Copy Private IP of 2 Hosts 

Copy Host 1 “Ansible-Node-1” private IP

Copy Host 2 “Ansible-Node-2” private IP

Open the file “/etc/ansible/hosts” and create group “Ktexperts-Nodes-Group” and mention above 2 nodes IP addresses under group.

Note
:wq! —- to quit.

Now on wards ansible server push code to 2 nodes but ansible main configuration file is not recognizing the 2 hosts.

So,we need to uncomment two files in the main configuration file “ansible.cfg”

3. Uncomment two files “inventory = /etc/ansible/hosts” and “sudo_user = root” in the ansible configuration file “/etc/ansible/ansible.cfg”

Note
:wq! —- to quit.

Now on wards ansible server push code to 2 hosts automatically by running playbooks.

 

Thank you for giving your valuable time to read the above information. Please click here to subscribe for further updates

KTEXPERTS is always active on below social media platforms.

Facebook : https://www.facebook.com/ktexperts/
LinkedIn : https://www.linkedin.com/company/ktexperts/
Twitter : https://twitter.com/ktexpertsadmin
YouTube : https://www.youtube.com/c/ktexperts
Instagram : https://www.instagram.com/knowledgesharingplatform

Share via:
Note: Please test scripts in Non Prod before trying in Production.
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

Add Comment