I’m a newcomer but there’s one thing that bothers me. It seems that plays always have the hosts to be acted on embedded in the play itself. What if you wanted to run a play against different hosts? For example, you might want to run the play against your test setup. If all goes well, you might want to run it against your East servers and then to West and then…
We don’t put out dev/test/staging/prod servers all in one inventory file. We have separate inventories for each individual “environment”.
Additionally, we would target something like:
hosts: web
And then if we wanted to only target our web servers in “east”, we would use --limit, such as:
ansible-playbook -i production --limit east some-playbook.yml
or even:
ansible-playbook -i production --limit web:&east some-playbook.yml
there are many ways around this, Matt demonstrated one (I happen to use the
same). You can also have a unified inventory file and used --limit against
that (--limit 'production').
Another popular method is by making the hosts entry parameterized:
hosts: "web:{{target}}"
now you can pass -e 'target=&production' in the command line or any other
combination that is allowed by host patterns