EdFred
EdFred

Reputation: 87

Ansible inventory limit child group to specific group members

I know it's possible to run a playbook against the first half of group1, but is it possible to create child groups like that in the inventory already? This is an example:

[group1]
srv1
srv2
srv3
srv4
 
[halfgroup1:child]
group1[0:2] #<-- This should contain srv1 and srv2

I can run the playbook against group1[0:2], or against srv1,srv2. But is it possible to do these in the inventory already, so i can run the playbook against halfgroup1?

With the example above, Ansible is unable to parse the inventory. So I guess it's just not possible, but if anybody has an idea, feel free to share it with me.

Upvotes: 2

Views: 399

Answers (1)

Zeitounator
Zeitounator

Reputation: 44615

I think you are just taking this upside-down. The following inventory declares 2 "halfgroups" and a parent group joining the two. You can target any of those.

[halfgroup1]
srv1
srv2

[halfgroup2]
srv3
srv4

[group1:children]
halfgroup1
halfgroup2

Upvotes: 1

Related Questions