Ansible inventory organization

Hi,

I have servers that are organized into environment (such as staging, production, test, etc.) and into function (www, db, etc)

My idea was to have a group ‘production’ with a list of servers, and a group www with a list of servers. Just like this:

production:
hosts:
servera
serverb

test:
hosts:
serverc
serverd

www:
hosts:
servera
serverb
serverc
serverd

Not I want something like
ansible-playbook --limit production,www

and I want it applied only to servera and serverb. Not sure how to get there. Can anyone give a hint?

Kind regards,
Sascha

Hi,

maybe to be clearer: I want the intersection of production & www.

Kind regards,
Sascha

I recommend this layout:

environments/production/hosts

environment/staging/hosts

environment/test/hosts

Each hosts file should have list of servers.

all:
hosts:
placeholder
children:
db:
hosts:
dbserver1

 www:

  hosts:

    wwwserver1

You could execute playbook like:
ansible-playbook -i environments/production/ webservers.yml

If you want an intersection, try:

ansible-playbook --limit production:\&www

Or if you just want to run on "servera" and "serverb", you can do it like this:

ansible-playbook --limit ~server[ab]

--Steve

https://docs.ansible.com/ansible/latest/user_guide/intro_patterns.html

Hi,

thanks Steve, this is what I was looking for. I have found intersection in the configs now.

Thanks again,
Sascha