0
votes

I am not sure if below can be achieved via ansible. I have got list of hosts as belows: NOTE: Host can be repeated across groups

Region: US
Stage: QA
Host: Host1
Region: US
Stage: UAT
Host: Host2
Region: London
Stage: QA
Host: Host3
Region: London
Stage: UAT
Host: Host1

Now I may want to run certain tasks on all the Hosts in US group. Or I may want to run Host with region us and stage as qa. Or I may want to run all the host belonging to QA group. So how can i achieve this?

1
What have you tried? Because this is covered in the docs early on and is pretty straight forward. Also your example doesn't actually have a host in multiple groups.ydaetskcoR
@ydaetskcoR: Apologies for the miss, but host can repeat itself across groups as a sample Host1 can be in 2 regions but different stage as shown in the updated example. For now I have a temporary fix with groups as "region_stage" and host. So I have multiple permutation and combinations of groupsMrunal Gosar

1 Answers

1
votes

Define the inventory file as:

[US]
Host1
Host2

[London]
Host1
Host3

[QA]
Host1
Host3

[UAT]
Host1
Host2

run certain tasks on all the Hosts in US group.

hosts: US

run Host with region us and stage as qa

hosts: US:&QA

run all the host belonging to QA group

hosts: QA

For one more pattern (exclusion) which you did not ask for explicitly, refer to the documentation on patterns.