Mixing dynamic & static inventory : sharing groups

1,611 views
Skip to first unread message

Michel Blanc

unread,
Feb 12, 2014, 7:58:24 AM2/12/14
to ansible...@googlegroups.com
Hi,

I'm trying to mix dynamic & static inventory, but I fall short having
these inventories cooperating with each other.

My playbook is supposed to :
- handle droplet creation on Digital Ocean
- provision each droplet

Because of this, I do not know target host IPs in advance, and I don't
want to fill 'ansible_ssh_host' manualy in my static inventory.

So my idea was to use the groups returned in by digital_ocean.py
inventory script, which creates groups based on DigitalOcean hostnames
(among others) :

On the dynamic side, I'm using digital_ocean.py inventory script :

$ inventory/digital_ocean.py --pretty
{
...
"web1.example.org": [
"12.34.56.78"
]
}

So all seems well, I though could use this group in the static part :

$ cat inventory/hosts
localhost gather_facts=no ansible_python_interpreter=python2

[backends:children]
web1.example.org

Now when I run `ansible all -i inventory/ --list-hosts` I get :

ERROR: child group is not defined: (web1.example.org)

It seems that the group created by digital_ocean.py is not available in
the static inventory part.

Is this intended, or am I missing something ?

Thanks for reading.

M
--
Michel Blanc
{ :github => "@leucos", :twitter => "@b9m", :gpg => "0X24B35C22" }

Serge van Ginderachter

unread,
Feb 12, 2014, 8:07:38 AM2/12/14
to ansible...@googlegroups.com

On 12 February 2014 13:58, Michel Blanc <m...@mbnet.fr> wrote:
 
​​
[backends:children]
  web1.example.org

Now when I run `ansible all -i inventory/ --list-hosts` I get :

ERROR: child group is not defined: (web1.example.org)

​files and scripts within an inventory are parsed separately from each other, and only merged afterwards.
So at the time of the parsing of your hosts file, the parser doesn't know yet ​about that group.

Just add an empty group definition:


[backends:children]
  web1.example.org


​should do the trick


  Serge​

Michel Blanc

unread,
Feb 12, 2014, 8:12:59 AM2/12/14
to ansible...@googlegroups.com, se...@vanginderachter.be
On 12/02/2014 14:07, Serge van Ginderachter wrote:

> ​files and scripts within an inventory are parsed separately from each
> other, and only merged afterwards.
> So at the time of the parsing of your hosts file, the parser doesn't
> know yet ​about that group.
>
> Just add an empty group definition:
>
> [web1.example.org]
>
> ​
> [backends:children]
> web1.example.org
>
> ​should do the trick
>

Awesome, that was it. Thanks a lot Serge !
Reply all
Reply to author
Forward
0 new messages