Group organization

Host group organization makes it possible to organize hosts in groups based on role, geographical location, or data center location. In a parent and child structure, it is possible to set parent group variables and make the child group inherit them. To override parent group variables, individual hosts or child groups can have their own unique custom variables. This practice is more of an Ansible inventory management feature than for playbook coding, yet it is very important for multi-architecture configuration management.

As described in previous chapters, host variables can either be defined within the inventory or the playbook itself. But it is easier to manage when organized within the inventory files as group_vars and hosts_vars.

The following example for an inventory file shows how parent and child group variables can be defined: 

/etc/ansible/hosts:
[linuxservers:children]
webservers
loadbalancers

[linuxservers:vars]
remote_user: setup
ntpserver: 0.uk.pool.ntp.org
become: yes

[webservers]
node0
node1
node2

[webservers:vars]
remote_user: devadmin
ansible_connection: ssh

[loadbalancers]
node3
node4

[loadbalancers:vars]
ntpserver: 0.us.pool.ntp.org
ansible_connection: docker

This is not the only structure that can be used to define groups. The inventory file can only hold the structure of the groups, and then each group can have their own inventory file that holds their variables. The same rule applies where a child variable overrides a parent variable.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.14.224.197