# Collecting setup facts from other servers when using --limit

**URL:** <https://forum.ansible.com/t/collecting-setup-facts-from-other-servers-when-using-limit/15224>\
**Category:** Ansible Project\
**Created:** [May 13, 2014, 5:14pm UTC](https://forum.ansible.com/t/collecting-setup-facts-from-other-servers-when-using-limit/15224 "2014-05-13T17:14:10Z")\
**Posts on this page:** 4\
**Page:** 1

<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 13, 2014, 5:14pm UTC](https://forum.ansible.com/t/collecting-setup-facts-from-other-servers-when-using-limit/15224/1 "2014-05-13T17:14:10Z")

</div>

I have a playbook that sets up the application configuration on a  
server in a cluster. This configuration is based on other servers in  
the cluster and uses hostvars to great effect in the templated  
configuration. I'm really happy at how easy ansible make that. To make  
that work so that the facts about the other hosts are gathered I have  
an empty play at the top of these playbooks that looks something like  
this:

&nbsp;&nbsp;&nbsp;&nbsp;# just gather facts from these groups  
&nbsp;&nbsp;&nbsp;&nbsp;- hosts: group1:group2:group3  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tasks:

&nbsp;&nbsp;&nbsp;&nbsp;# now do the real work  
&nbsp;&nbsp;&nbsp;&nbsp;- hosts: group4  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# lots of tasks

This seems a little weird that there's not an explicit way to gather  
facts (it just a side effect, but it works fine so no biggie.

That's the preamble... The awkward part is when I want to add a new  
server to this cluster and I want to run a playbook against just one  
host of the group (the new server). Normally I could just use a  
--limit server8 or something, but then this skips the fact gathering  
step implicit in the empty tasks at the beginning of the playbook. So  
instead I have to do something like:

&nbsp;&nbsp;--limit server8:group1:group2:group3

Or (slightly shorter but more opaque)

&nbsp;&nbsp;--limit '!group4&server8'

I'm trying to train myself to remember to do one of these, but I have  
to train my team too. It would be nice if my playbook had a way of  
explicitly gathering facts that wasn't skipped by a --limit arg (more  
control in the playbook and less need for command line args) and then  
I could just do the more intuitive

&nbsp;&nbsp;--limit server8

Am I doing it wrong? Or is this a pain others feel?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [May 13, 2014, 7:52pm UTC](https://forum.ansible.com/t/collecting-setup-facts-from-other-servers-when-using-limit/15224/2 "2014-05-13T19:52:23Z")

</div>

This has come up once or twice.

When limiting, you can’t get facts from other hosts.

The solution is to not use --limit and instead do:

hosts: “mygroup:{{ limit\_spec }}”

and pass “-e limit\_spec=what\_I\_would\_have\_passed\_to\_limit”

This allows patterns like:

- hosts: all  
tasks: # gather facts

- hosts: mygroup:{{ limit\_spec }}"  
tasks:

---

<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 13, 2014, 8:50pm UTC](https://forum.ansible.com/t/collecting-setup-facts-from-other-servers-when-using-limit/15224/3 "2014-05-13T20:50:25Z")

</div>

Thanks for the additional options. But doesn't it seem weird that you  
should/shouldn't use --limit based on the implementation details of  
the playbook? Should the person who is running the playing have to  
know about the inner workings of the playbook file in order to know  
whether to use --limit or not? Just seems prone to error and like  
there should be a better way. Maybe it's a more explicit way of  
gathering facts, maybe it's something else.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [May 13, 2014, 9:02pm UTC](https://forum.ansible.com/t/collecting-setup-facts-from-other-servers-when-using-limit/15224/4 "2014-05-13T21:02:35Z")

</div>

" But doesn’t it seem weird that you  
should/shouldn’t use --limit based on the implementation details of  
the playbook?"

Depends what you want limit to do. It’s kind of a damned if you do/don’t, sort of thing.

I suppose we could make a smart exemption for a single play with no tasks other than fact gathering, so that --limit doesn’t apply to them, but some people won’t like that.

Thus it really is a request for fact caching, which we are not quite ready for yet – (requires everybody to stop wanting other things so we can catch some breaths, etc) 🙂
