Apologies in advance - I feel like this has been solved before but I am not coming up with much after searching ansible.cc and the group records.
I am trying to make a playbook that I can use between different environments. I have application X deployed in a set of environments, dev, load testing, deployment testing, production, etc… and I want to use the same playbook to do some work and select the environment based on a variable. The host groups in question are named in a pattern to make this possible
And then we have some more global groups, regrouping all test
machines, all dev machines and all production machines.
[dev:children]
app_x_dev
app_y_dev
At playbook level we define a generic play for a certain app,
deploying it to the [app_x] group.
When ran, we limit (--limit option to ansible-playbook) playbook
execution to e.g. [dev] group. This is handled by some wrapper scripts
calling ansible-playbook.
Many thanks for the pointer. I stand by my prior statement that I was doing something a bit silly. What I was trying to do is to use the variable to replace a substring in the hostname - the “app_x_” section of the hostname is fixed, where the “app_x_$env” is variable.
Basically was trying to be too tricky and I can easily use the variable name vs trying to do the substring replacement.