Scoping of playbooks

My first Ansible project is configuring the DNS client of our Linux machines. This configuration is different depending on the managed node’s location within our network (west dmz, west non-dmz, east dmz, east non-dmz). I’m trying to figure out how to scope my playbook so that each location has its own configuration applied. We don’t have Ansible Tower and I’m not sure if we are getting it. I am confident that I can create the logic to determine the location based on the managed node’s default gateway. Our environment is approaching 2000+ systems. So, I’m wondering:

  1. I’m assuming (hoping) that there is a way to do this in a single playbook using some kind of conditional like “switch/caseof server_location”. How do I do this?

  2. It is possible that this configuration information is stored in a text file external to the playbook?

  3. The thought of creating and managing inventory files for all of this seems rather daunting. Is there a better way to create & manage an inventory of this size assuming that our organization is not willing to pay for Ansible Tower? Would this be dynamic inventory via some kind of vSphere/vCenter plugin?

Thanks.

Many ways to do this, I recommend using different groups for each and then assigning variables with the different configurations, use those variables in the plays.

To store this data ‘externally from playbook’ I would use group/host_vars.

As for inventory, it does not need to be files, via the dynamic scripts you can use any source of data to generate the inventory for Ansible, check the existing ones as they should cover most common cases.

Brian:

After reading http://docs.ansible.com/ansible/intro_inventory.html I’m thinking that I will end up with huge inventory files (hundreds or even thousands of systems) that are difficult to maintain – something I was hoping to avoid. My thought was that if I had a (CSV) file with default gateway addresses and associated location names and another (CSV) file with location names with configuration information (DNS server IP addresses, DNS suffix search order) that Ansible could iterate over both to make the necessary changes. This way I only need to worry about the ‘all’ inventory.

If in your inventory file you were targeting all possible nodes which require configuring:

Then in a playbook (run on each of those nodes):

Does that help?

Jinesh:

This looks promising. I’m sure I’ll have more questions as I get deeper into this.

Thanks.