Is it possible to specify hosts when including a nested playbook?

67 views
Skip to first unread message

Edd Grant

unread,
Jan 21, 2016, 7:38:35 AM1/21/16
to Ansible Project
I have an 'all-hosts' playbook which contains logic common to all hosts. This playbook is nested as an include in several top-level playbooks (for example deploy-application-x and deploy-application-y). When I run each of these top level playbooks I want to limit the hosts on which all-hosts runs to just the hosts defined in the top level playbook.

Here's a slightly contrived example in code:

#deploy-app-x.yml
---
# First do the stuff which is common to all hosts, but just run it on the app-x-hosts this time
- include: all-hosts.yml
hosts=app-x-hosts

# Then deploy app-x
- hosts: app-x-hosts
  roles:
    - { role: deploy-app-x, tags: ['app-x']}


#deploy-app-y.yml
---
# First do the stuff which is common to all hosts
, but just run it on the app-y-hosts this time
- include: all-hosts.yml hosts=
app-y-hosts

# Then deploy app-y
- hosts: app-y-hosts
  roles:
    - { role: deploy-app-y, tags: ['app-y']}


#all-hosts.yml
---
- hosts: &$hosts #This convention is defined in 'Patterns' http://docs.ansible.com/ansible/intro_patterns.html but doesn't seem to work at all here.
  roles:
    - { role: group-management, groups_to_manage: [{ name: 'dev' }, { name: '247ops' }], tags: ['groups', 'users'] }
    - { role: user-management, users: "{{ devteam_users }}", tags: ['users'] }
    - { role: user-management, users: "{{ twenty_four_seven_ops_users }}", tags: ['users'] }

When I try to execute either of the top level playbooks the invocation of the all-hosts playbook simply gets skipped:

PLAY ***************************************************************************
skipping: no hosts matched


Is this something Ansible supports or have I gone a bit off piste here? If the latter are there any common Ansible idioms for nesting and re-using plays across different sets of machines?

Many thanks,

Edd

Reply all
Reply to author
Forward
0 new messages