Question concerning multiple -hosts: entries in a playbook

11 views
Skip to first unread message

mark....@neonova.net

unread,
Oct 31, 2017, 2:40:02 PM10/31/17
to Ansible Project
There might be a better way to do this, but I'm unaware of it, so I'm asking the list.  I have a playbook that has two parts to it:
1. Pulls branch from git repo to the localhost (ie the Ansible server)
1a. compiles the code (it's a PHAR file, so nothing too onerous)
2. Pushes the code to our external servers.

Part 1/1a has a hosts: entry of 'localhost' and part 2 has a hosts: entry for our external servers that are getting the updated code.  

My question is, is there a way to abstract the second hosts: line so I can specify specific hosts/groups? IOW, if I set that hosts: line to 'production', is there a way to specify on the command line -i dbservers or other subset instead of manually editing that line every time?

Second question, if the above question is just wrong/bad/not sane, is there a better way to do this?  

Brian Coca

unread,
Oct 31, 2017, 2:53:58 PM10/31/17
to Ansible Project
You can set the 2nd play like this:

- hosts: '{{target|default('devel')}}'

then call it:

ansible-playbook ... -e 'target=production'





--
----------
Brian Coca

Mark Haney

unread,
Oct 31, 2017, 2:59:32 PM10/31/17
to ansible...@googlegroups.com
On 10/31/2017 02:53 PM, Brian Coca wrote:
> You can set the 2nd play like this:
>
> - hosts: '{{target|default('devel')}}'
>
> then call it:
>
> ansible-playbook ... -e 'target=production'
Huh.  I hadn't thought about using that method.  I'll give it a shot. 
Thanks.

--
Mark Haney
Network Engineer at NeoNova
919-460-3330 option 1
mark....@neonova.net
www.neonova.net

Reply all
Reply to author
Forward
0 new messages