Ansible – Post – 6 – Ansible inventory folder strucuture

ansible inventory folder structure
Spread the love

 

 

 

Ansible - Post - 6 - Ansible Inventory Folder Structure:

In this blog post, we will see how to create the ansible inventory folder structure, as the configuration data grows , it will be hard to maintain the information in a single inventory file, that is where the folder structure comes into play, you can download demo2.tar.gz from the bottom of the post, ​​ you can later scp that tar.gz to your virtual box and extract it in acs home directory.​​ 

 

scp demo2.tar.gz​​ [email protected]:/tmp

 

cd /home/vagrant

 

tar -xvf /tmp/demo2.tar.gz .

 

post extraction​​ ,​​ this is how the tree structure of the folders​​ will be.​​ 

 

 

 

We can​​ see​​ that the inventoy_prod file is similar to the inventory file that we had created earlier.​​ 

 

 

We have YAML files defined under group_vars directory and host_vars directory, the host_vars directory always take precedence that the group_vars directory.​​ ​​ Lets​​ taken an example of creating a user in the target system, lets see which YAML file under the vars directories takes precedence.​​ ​​ 

 

In “all” YAML file , we have defined the username as all_username. Please note that all the YAML file starts with 3 dashes at the top.​​ 

 

 

 

 

In “webservers” YAML file , we have defined the username as group_user, please remember that with in the group_vars directory the “webservers” YAML file takes precedence than the “all” YAML file.

 

 

 

 

Under host_vars directory, we have defined “web1” ​​ YAML file which has defined the username as web1_user

 

 

 

Now lets go ahead and create the user in for the servers under the group webservers.​​ You can see that “web1_user” took precedence from the “web1” YAML file under the host_vars directory.​​ 

 

As you can see we are​​ also​​ getting a permission denied error , this is because we don’t have the root privileges for the user vagrant to create a new user in the target system .​​ 

 

 

To overcome this , we can use the “ - - sudo” command at the end which will give the root permissions.​​ 

 

 

Now the use is created successfully on the target system.

 

Thanks for viewing the post, please post your comments below.

Please Like & Follow us on Facebook & Twitter,

https://www.facebook.com/gadoth/

https://www.twitter.com/GadothDA/

Download Ansible demo2

Related posts

Leave a Comment