Hosts with multiple roles

Hi,

I’m having problems with the ansible inventory, filters and hosts in multiple roles. Let’s assume I have two customers, each with a machine that can be a http server and/or a samba server.This is my inventory:

[customer1]
host1.customer1.com

[customer2]
host1.customer2.com
host2.customer2.com

[http-servers]
host1.customer1.com
host1.customer2.com

[samba-servers]
host1.customer1.com
host2.customer1.com

As you can see, customer1 only has a single machine that fulfills both roles and customer2 has a separate machine for each role.

Now I’m trying to run the playbook with filters:

% ansible-playbook -i ./hosts --list-hosts --limit customer1 ./site.yml

playbook: ./site.yml

play #1 (customer1): host count=1
host1.customer1.com

play #3 (http-servers): host count=1
host1.customer1.com

play #4 (samba-servers): host count=1
host1.customer1.com

Why on earth do I get play #3 and #4? I specifically asked for customer1 which only has one entry.

The same goes for role-based groups:

% ansible-playbook -i ./hosts --limit http-servers --list-hosts ./site.yml

playbook: ./site.yml

play #1 (customer1): host count=1
host1.customer1.com

play #2 (customer2): host count=1
host1.customer2.com

play #3 (http-servers): host count=2
host1.customer1.com
host1.customer2.com

play #4 (samba-servers): host count=1
host1.customer1.com

What’s going on here?

I did read the documentation on inventory, groups and patterns but that page only has examples for hosts in single roles. What am I doing wrong?

-dirk

--limit does a intersection with existing - hosts: clauses, it looks like

play1: - hosts: customer1
play2: - hosts: customer2
play3: - hosts: http-servers
play4: - hosts: samba-servers

when you do --limit customer1 you should get play1, 3 and 4, as the
intersection of customer1 and customer1 is 1 host, customer2 and
customer1 is 0 hosts, http-servers and customer1 is 1 host, etc.

If you want to ONLY run specific plays I suggest you look at tags.