jtri2q
Last Updated: July 29, 2016
·
6.436K
· lorin
Me pixel

Limiting hosts when including a playbook

You can define a playbook that calls another and limits the host. Here's a child playbook,that's meant to be invoked by the parent. Note how hosts is defined:

# ping.yaml
- name: ping
  hosts: webservers:&$hosts
  tasks:
   - name: ping
     action: ping

Here's how you would define another playbook that invokes ping.yaml but only for the staging server:

# pong.yaml
- include: ping.yaml hosts=staging
Say Thanks
Respond

5 Responses
Add your response

3929
6855bc98477e9de7f59a296ee432ab17

I haven't seen that syntax when defining hosts before. Have any pointers? Also, does this mean that staging is defined in webservers:children or can it be a top level group itself?

over 1 year ago ·
3933
Me pixel

The :& syntax isn't currently documented, I just submitted a pull request to document that: https://github.com/ansible/ansible/pull/2033

In the example above, staging can be an individual host or any kind of group, including a top-level group.

over 1 year ago ·
4140
68ae3430cc86a3e465e7b8860e178981

Very cool. Now I can build generic utility playbook bundles
with 'hosts: all:&hosts' and use them anywhere.

over 1 year ago ·
23330
None

is there a way to make "staging" into a variable?
- include: ping.yaml hosts=staging

Tried the usaul {{var}} synatx; does not seem to work
ie:
- include: tasks/zoo1.yml zhost={{zhost}}

over 1 year ago ·
28031
Profile

Try quoting the {{zhost}}, like so:
- include: tasks/zoo1.yml zhost="{{zhost}}"

over 1 year ago ·
Filed Under