Reputation: 15
My hosts file is like
[app]
192.168.6.100
192.168.6.101
[DB]
192.168.7.200
192.168.7.201
And I want to run two different .yml files separately for each of these hosts using - include app.yml
and - include db.yml
from a main.yml
file
To differentiate between the hosts I used when: "{{ groups['app'] }}"
and when: "{{ groups['db'] }}"
, but its not working properly. I'm also not sure whether its a right approach or not
# cat main.yml
---
- include: app.yml
when: "{{ groups['app'] }}"
- include: db.yml
when: "{{ groups['db'] }}"
Upvotes: 0
Views: 681
Reputation: 60079
You're close. The correct syntax would be:
---
- include: app.yml
when: "'app' in group_names"
- include: db.yml
when: "'db' in group_names"
Upvotes: 1