Hi,
I have a list of groups
admin:
groups: ['group-boapp-layout-A', 'group-boapp-layout-B']
Each of these groups has a number of hosts as defined in the inventory
(note that this info needs to be global as opposed to per group_vars/group-boapp-layout-A.yml so that it can be accessed by other groups)
[group-boapp-layout-A]
ec2-test-boapp01
ec2-test-boapp02
[group-boapp-layout-B]
ec2-test-boapp03
ec2-test-boapp04
[tier-boapp:children]
group-boapp-layout-A
group-boapp-layout-B
GROUPS Variables ("groups"):
--------------------------------
{
"all": [
"ec2-test-boapp03",
"ec2-test-boapp04",
"ec2-test-boapp01",
"ec2-test-boapp02"
],
"group-boapp-layout-A": [
"ec2-test-boapp01",
"ec2-test-boapp02"
],
"group-boapp-layout-B": [
"ec2-test-boapp03",
"ec2-test-boapp04"
],
I would like to get a list of hosts that admin should live on (union of group-boapp-layout-A and group-boapp-layout-B)
=> ['ec2-test-boapp01','ec2-test-boapp02','ec2-test-boapp03','ec2-test-boapp04']
I have tried to use with_flattened though I only end up with the hosts from the last group
set_fact:
hosts: "{{ groups[item] }}"
with_flattened: admin.groups
- debug: msg="{{ app_name }} hosts = {{ hosts }}"
-----------------------------------
ok: [ec2-test-boapp01] => {
"msg": "admin hosts = ['ec2-test-boapp03', 'ec2-test-boapp04']"
}
ok: [ec2-test-boapp03] => {
"msg": "admin hosts = ['ec2-test-boapp03', 'ec2-test-boapp04']"
}
ok: [ec2-test-boapp02] => {
"msg": "admin hosts = ['ec2-test-boapp03', 'ec2-test-boapp04']"
}
ok: [ec2-test-boapp04] => {
"msg": "admin hosts = ['ec2-test-boapp03', 'ec2-test-boapp04']"
}
This was working with v1.7.x I am now using
I'd appreciate any input or if there is a better way to do this.
Thanks
James