Why are hosts embedded in a play?

34 views
Skip to first unread message

Todd Sampson

unread,
May 7, 2014, 10:11:33 AM5/7/14
to ansible...@googlegroups.com
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...

Matt Martz

unread,
May 7, 2014, 10:23:44 AM5/7/14
to ansible...@googlegroups.com, Todd Sampson
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

-- 
Matt Martz
ma...@sivel.net

On May 7, 2014 at 9:11:36 AM, Todd Sampson (samps...@gmail.com) wrote:

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...
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/a9e21c8b-468d-43ad-ac59-37ec08346aa9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Brian Coca

unread,
May 7, 2014, 11:29:25 AM5/7/14
to ansible...@googlegroups.com
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



--
Brian Coca
Stultorum infinitus est numerus
0110000101110010011001010110111000100111011101000010000001111001011011110111010100100000011100110110110101100001011100100111010000100001
Pedo mellon a minno
Reply all
Reply to author
Forward
0 new messages