# Force fact-gathering on all hosts when using -limit

**URL:** <https://forum.ansible.com/t/force-fact-gathering-on-all-hosts-when-using-limit/18155>\
**Category:** Ansible Project\
**Created:** [May 4, 2015, 7:58am UTC](https://forum.ansible.com/t/force-fact-gathering-on-all-hosts-when-using-limit/18155 "2015-05-04T07:58:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christian\_Franke](https://avatars.discourse-cdn.com/v4/letter/c/e19adc/32.png) [@Christian\_Franke](https://forum.ansible.com/u/Christian_Franke)\
**Post date:** [May 4, 2015, 7:58am UTC](https://forum.ansible.com/t/force-fact-gathering-on-all-hosts-when-using-limit/18155/1 "2015-05-04T07:58:45Z")

</div>

Hi all,

I’m sitting in front of a fairly complex ansible project that we’re using to set up our local development environments (multiple VMs) and there’s one role that uses the facts gathere by ansible to set up the etc/hosts file on every VM. Unfortunately, when you want to run the playbook for one host only (using the -limit parameter) the facts from the other hosts are (obviously) missing.

Is there a way to force ansible to gather facts on all hosts, even if you limit the playbook to one specific host?

We tried to add a play to the playbook to gather facts from all hosts, but of course that also gets limited to the one host given by the -limit parameter. If there’d be a way to force this play to run on all hosts before the other plays, that would be perfect.

I’ve found the solution to use fact caching with redis, but since our playbook is used locally, I wanted to avoid the need for additional software. I know, it’s not a big deal, but I was just looking for a “cleaner”, ansible-only solution and was wondering, if that would exist.

Cheers,

Christian

---

<div class="post-metadata">

**Author:** ![Josh\_Smift1](https://avatars.discourse-cdn.com/v4/letter/j/bcef8e/32.png) [@Josh\_Smift1](https://forum.ansible.com/u/Josh_Smift1)\
**Post date:** [May 4, 2015, 1:46pm UTC](https://forum.ansible.com/t/force-fact-gathering-on-all-hosts-when-using-limit/18155/2 "2015-05-04T13:46:51Z")

</div>

> Is there a way to force ansible to gather facts on all hosts, even if  
> you limit the playbook to one specific host?

If you don't have to use --limit per se to do it, you can get much the  
same effect with something like this:

&nbsp;&nbsp;- hosts: all  
&nbsp;&nbsp;&nbsp;&nbsp;gather\_facts: true

&nbsp;&nbsp;- hosts: "{{ targets }}"  
&nbsp;&nbsp;&nbsp;&nbsp;[\* stuff \*]

Then you can run this with --extra-vars="targets=\<expression\>", and the  
second play will only run on hosts that match the expression.

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-Josh (jbs@care.com)

This email is intended for the person(s) to whom it is addressed and may contain information that is PRIVILEGED or CONFIDENTIAL. Any unauthorized use, distribution, copying, or disclosure by any person other than the addressee(s) is strictly prohibited. If you have received this email in error, please notify the sender immediately by return email and delete the message and any attachments from your system.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [May 4, 2015, 1:49pm UTC](https://forum.ansible.com/t/force-fact-gathering-on-all-hosts-when-using-limit/18155/3 "2015-05-04T13:49:14Z")

</div>

Another way around this is using persistent fact caching.

---

<div class="post-metadata">

**Author:** ![Michael\_Peters](https://avatars.discourse-cdn.com/v4/letter/m/c2a13f/32.png) [@Michael\_Peters](https://forum.ansible.com/u/Michael_Peters)\
**Post date:** [May 4, 2015, 2:34pm UTC](https://forum.ansible.com/t/force-fact-gathering-on-all-hosts-when-using-limit/18155/4 "2015-05-04T14:34:19Z")

</div>

I have to say, that it kind of bothers me that fact "caching" is the  
solution to whether or not it works. Caching is normally about  
speeding things up or making them more scalable. Not about having it  
actually be correct. In this instance, wouldn't relying on fact  
caching break every time the cache is flushed, or on a new system that  
was not loaded with the cache?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [May 4, 2015, 2:37pm UTC](https://forum.ansible.com/t/force-fact-gathering-on-all-hosts-when-using-limit/18155/5 "2015-05-04T14:37:02Z")

</div>

It is not the solution, but it is a workaround available now.

On my list i have being able to 'delegate' facts so we can do something like:

setup: set\_for={{item}}  
delegate\_to: "{{item}}'  
with\_items: "{{groups['dbservers']}}

but my list is long and this is not a simple task.

---

<div class="post-metadata">

**Author:** ![Michael\_Peters](https://avatars.discourse-cdn.com/v4/letter/m/c2a13f/32.png) [@Michael\_Peters](https://forum.ansible.com/u/Michael_Peters)\
**Post date:** [May 4, 2015, 2:38pm UTC](https://forum.ansible.com/t/force-fact-gathering-on-all-hosts-when-using-limit/18155/6 "2015-05-04T14:38:00Z")

</div>

Gotcha, thanks!
