Ansible to manipulate dynamic inventory

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?

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.