Organize playbooks in subdirectories

288 views
Skip to first unread message

André

unread,
Apr 4, 2015, 10:35:48 AM4/4/15
to ansible...@googlegroups.com
Hi,
I am trying to find a suitable directory structure for my ansible files. I have come up with this structure which is not working with the playbooks in subdirectories:

.
├── group_vars
├── inventories
  ├── production
    ├── group_vars
      └── all.yml
    └── inventory
  └── vagrant
      ├── group_vars
        └── all.yml
      └── inventory
├── playbooks
  ├── net1
    └── dnsdhcp.yml
  ├── net2
    └── dnsdhcp.yml
  └── update.yml
├── roles
  ├── dnsmasq
  ├── bind9
  ── isc-dhcp
├── playbooks
└── Vagrantfile

In the group_vars for the inventories I have variables which differ between the real servers and my vagrant test vms (IP addresses, domain names), this is working fine.

Then I would like to organize the playbooks into subdirectories so I don't wind up with a directory with dozen of playbooks. The root group_vars variables would then define the project wide configuration which can be used by multiple playbooks.

For example if I have two subnetworks and I need a DHCP server on each (possible different programs), I would write a playbook for each which installs the server (using roles) and put them in different subdirectories.

Then I have the master file which includes most playbooks. This file could be used to run ansible every day with a cron job.

The problem is that the group_vars are relative to the current running playbook, so I can't run

ansible-playbook -i inventories/vagrant/inventory playbooks/net2/dnsdhcp.yml

One way would be to flatten out the hierarchy in the playbooks directory and put a symlink to the root group_vars directory in the playbooks directory:

.
├── group_vars
├── playbooks
  └── group_vars -> ../group_vars
  ├── net1-dnsdhcp.yml
  ├── net2-dnsdhcp.yml
  ├── update.yml

But then I would have to prefix the files for different subnets and would have one directory with many playbooks.



Is this a good way to organize the playbooks? I'm not sure if I understand the purpose of the playbooks correctly, am I putting the right plays in the playbooks or should I organize the plays in an other way into playbooks?

Reply all
Reply to author
Forward
0 new messages