yolzoa
Last Updated: February 25, 2016
·
3.7K
· tartansandal

Targeting hosts with multiple roles

You can use group intersections to target hosts that have overlapping roles. For example, suppose your inventory hosts file defines the following overlapping groups:

# Melbourne data centre hosts
[melbourne]
db-01
db-02
web-01
web-02
...

# Sydney data centre hosts
[sydney]
db-11
db-12
web-21
web-22
...

# Database servers
[dbservers]
db-01
db-02
db-11
db-12

# Web servers
[webservers]
web-01
web-02
...

# LHS of load-balanced pairs
[left]
web-01
web-03
web-05
...

# RHS of load-balanced pairs
[right]
web-02
web-04
web-06
...

You can target hosts that are in the intersection of two or more groups using the limit option. For example:

ansible-playbook --limit 'sydney:&webservers:&left' playbook.yml

will run the playbook against the left hand side of the load-balanced webserver pairs in the Sydney data centre. This obviates the need to create multiple artificial groups like 'sydney-webservers-left'.

1 Response
Add your response

18690

Thanks

over 1 year ago ·