Ansible to manipulate dynamic inventory

83 views
Skip to first unread message

Bence Takács

unread,
Oct 19, 2015, 4:18:37 PM10/19/15
to Ansible Project
Upon running some tasks I need to manipulate Ansible host variables.

I created a dynamic inventory script that could support thata functionality and then I stucked:
- inventory modules support only add_host which works only in-memory
- I see no sign that ansible is capable of doing this: everything points to inventory providers like Tower, EC2, vagrant and Cobbler
- I found one suggestion to handle inventory manipulation outside ansible

I can create a solution that could handle the new parameters in-memory and then call my inventory script and update it at the end of playbook run. But I'm thinking: is it so weird idea?
Why haven't it designed this way? Or am I missing something?



Brian Coca

unread,
Oct 19, 2015, 5:05:34 PM10/19/15
to Ansible Project
Well, normally you start with either already existing hosts that you
can list in inventory or a virtualization solution (including clouds)
which normally already have a dynamically updated DB with the list of
the machines, add_hosts is only in memory because the inventory
scripts are not normally 'refreshed' in the middle of a run, the
expectation is that the subsequent runs would automatically retrieve
the new hosts form the existing 'source of truth'.

In 2.0 we've added `meta: refresh_inventory` that can force the
dynamic inventory update in the middle of play.



--
Brian Coca
Reply all
Reply to author
Forward
0 new messages