Ansible inventory organization

30 views
Skip to first unread message

Sascha Andres

unread,
Mar 25, 2019, 8:20:58 AM3/25/19
to Ansible Project
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

Sascha Andres

unread,
Mar 25, 2019, 8:24:44 AM3/25/19
to Ansible Project
Hi,

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

Kind regards,
Sascha

Sudheer S

unread,
Mar 25, 2019, 8:47:08 AM3/25/19
to ansible...@googlegroups.com
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
-
Sudheer S

Kai Stian Olstad

unread,
Mar 25, 2019, 8:47:22 AM3/25/19
to ansible...@googlegroups.com

S C Rigler

unread,
Mar 25, 2019, 8:47:28 AM3/25/19
to ansible...@googlegroups.com
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
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/8f849cde-abf8-40a5-b80b-fddfef02149b%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Sascha Andres

unread,
Mar 25, 2019, 8:52:41 AM3/25/19
to Ansible Project
Hi,

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

Thanks again,
Sascha
Reply all
Reply to author
Forward
0 new messages