ActionModule Update hostvars for specific hosts

Hi,

I am building an ActionModule (bypassing the host loop) to query an internal REST service that provides bulk metrics for a bunch of hosts at once (for the hosts that are in play). After getting the data back from the call, I want to then populate the hostvars of the hosts returned with filtered items from the data that correspond to each host. The call is made once to avoid repeated queries to the REST API.

The ActionModule seems to work in the context of a single host. Bypassing the host loop runs once, but adding data to the results simply updates one of the hosts and not all. Is there an object exposed from the ActionModule, base classes or embedded objects that will let me iterate over each hosts’ vars/facts and update them?

Ansible Version: 2.1.0.0 and 2.1.1.0

Thanks in advance!

Anyone have some possible insight to this? Any thoughts are appreciated.

Thanks!

To my knowledge you cannot update hostvars directly from an action plugin, primarily due to forking, and variable scope. If you do find a place where you could modify hostvars, they don’t modify the real hostvars, just a copy of it.

The way that set_fact works, is by returning ansible_facts in the result, and the executor merges it into hostvars. Unfortunately ansible_facts is per host, so if you are bypassing the host loop, all facts will be set for all hosts, not just the host you want.

Thanks, Matt!