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
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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
#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
#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?