Hi ,
I am generating an inventory file dynamically for each cluster using templates and store it in inventory folder. Below is how the inventory files looks.
Filename: leo
`
[gapp]
gapp[01:02]-leo.dev.com role=gapp
[papp]
papp[01:02]-leo.dev.com role=papp
[relay]
relay[01:02]-leo.dev.com role=relay
[web]
web[01:02]-leo.dev.com
[leo:children]
relay
web
papp
gapp
I then use the following task to output the value
`
- debug: msg=“{{ item }}”
with_inventory_hostnames: “{{env}}”
`
output:
`
TASK [provisioning : debug] ****************************************************
ok: [localhost] => (item=papp02-leo.dev.com) => {
“item”: “papp02-leo.dev.com”,
“msg”: “papp02-leo.dev.com”
}
ok: [localhost] => (item=gapp02-leo.dev.com) => {
“item”: “gapp02-leo.dev.com”,
“msg”: “gapp02-leo.dev.com”
}
ok: [localhost] => (item=gapp01-leo.dev.com) => {
“item”: “gapp01-leo.dev.com”,
“msg”: “gapp01-leo.dev.com”
}
ok: [localhost] => (item=relay01-leo.dev.com) => {
“item”: “relay01-leo.dev.com”,
“msg”: “relay01-leo.dev.com”
}
ok: [localhost] => (item=papp01-leo.dev.com) => {
“item”: “papp01-leo.dev.com”,
“msg”: “papp01-leo.dev.com”
}
ok: [localhost] => (item=web01-leo.dev.com) => {
“item”: “web01-leo.dev.com”,
“msg”: “web01-leo.dev.com”
}
ok: [localhost] => (item=relay02-leo.dev.com) => {
“item”: “relay02-leo.dev.com”,
“msg”: “relay02-leo.dev.com”
}
ok: [localhost] => (item=web02-leo.dev.com) => {
“item”: “web02-leo.dev.com”,
“msg”: “web02-leo.dev.com”
}
`
How can i get the “role” attributes for each of the hosts? Is there a better way to acheive this rather than using with_inventory_hostname. with_inventory_hostname allows me to assign the patters like web[01:10] rather than specifying each server instance.
`