Ansible Configtree Pattern
Here’s a useful pattern for installing configuration files on your ansible managed hosts.
File: roles/configtree/tasks/main.yml
File: myplaybook.yml
Now in the files
directory of the configtree
role I have a sparse copy of the filesystem for certain host profiles.
For example, I store the https nginx config for my blog in this path:
roles/configtree/files/prod/_blog/etc/nginx/sites-enabled/https
and host specific config, like the hosts file, can go in this path:
roles/configtree/files/prod/nyc1-4gb-public/etc/hosts
where nyc1-4gb-public
is the hostname of the machine.
Note in both of these paths I am using the prod
inventory, I might have different config for dev
or I might share config between the two environments by using a role and matching path like this:
- {role: configtree, CONFIGTREE_PATH: "_prod_and_dev_config/" }