# ActionModule Update hostvars for specific hosts

**URL:** <https://forum.ansible.com/t/actionmodule-update-hostvars-for-specific-hosts/22350>\
**Category:** Ansible Developer\
**Created:** [August 22, 2016, 8:56pm UTC](https://forum.ansible.com/t/actionmodule-update-hostvars-for-specific-hosts/22350 "2016-08-22T20:56:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jim\_Ficarra](https://avatars.discourse-cdn.com/v4/letter/j/9d8465/32.png) [@Jim\_Ficarra](https://forum.ansible.com/u/Jim_Ficarra)\
**Post date:** [August 22, 2016, 8:56pm UTC](https://forum.ansible.com/t/actionmodule-update-hostvars-for-specific-hosts/22350/1 "2016-08-22T20:56:33Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Jim\_Ficarra](https://avatars.discourse-cdn.com/v4/letter/j/9d8465/32.png) [@Jim\_Ficarra](https://forum.ansible.com/u/Jim_Ficarra)\
**Post date:** [August 30, 2016, 4:54pm UTC](https://forum.ansible.com/t/actionmodule-update-hostvars-for-specific-hosts/22350/2 "2016-08-30T16:54:14Z")

</div>

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

Thanks!

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [August 30, 2016, 5:18pm UTC](https://forum.ansible.com/t/actionmodule-update-hostvars-for-specific-hosts/22350/3 "2016-08-30T17:18:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Jim\_Ficarra](https://avatars.discourse-cdn.com/v4/letter/j/9d8465/32.png) [@Jim\_Ficarra](https://forum.ansible.com/u/Jim_Ficarra)\
**Post date:** [August 31, 2016, 11:32am UTC](https://forum.ansible.com/t/actionmodule-update-hostvars-for-specific-hosts/22350/4 "2016-08-31T11:32:47Z")

</div>

Thanks, Matt!
