Mixing dynamic & static inventory : sharing groups

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

​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

  Serge​

Awesome, that was it. Thanks a lot Serge !

M