# Hostvars and --limit

**URL:** <https://forum.ansible.com/t/hostvars-and-limit/19360>\
**Category:** Ansible Project\
**Created:** [September 25, 2015, 7:04pm UTC](https://forum.ansible.com/t/hostvars-and-limit/19360 "2015-09-25T19:04:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anubhav\_Gupta](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@Anubhav\_Gupta](https://forum.ansible.com/u/Anubhav_Gupta)\
**Post date:** [September 25, 2015, 7:04pm UTC](https://forum.ansible.com/t/hostvars-and-limit/19360/1 "2015-09-25T19:04:39Z")

</div>

Hi,

When I run the ansible playbook with a --limit option (in order to restrict the nodes on which the install would happen), the hostvars object does not contain the variables for the hosts not specified in the --limit option. Some of my playbook templates use hostvars for all the hosts in the inventory, and as a result these template rules fail when I run with the --limit option. What is the best way to get around this problem?

Thanks,  
Anubhav

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [September 26, 2015, 11:08pm UTC](https://forum.ansible.com/t/hostvars-and-limit/19360/2 "2015-09-26T23:08:30Z")

</div>

I think the issue is Ansible doesn't gather facts from hosts that  
aren't in the play.

We have a central log/graphite server that all hosts wired their  
monitoring agents into,  
and in our case just using an inventory hostname wasn't enough since  
traffic needed to  
flow over a dedicated instrumentation network, so we'd have to figure  
out the IP of the  
interface connected to that subnet.

This was a pretty big stack so when you changed something on a  
specific group of servers,  
a quick 'limit run' saved a few minutes and we constantly forgot to  
add the monitoring  
servers into the limit list.

Best workaround I found was to limit the amount of hostvars I used and  
replace them with  
inventory variables. These were physical servers so keeping specific  
data in the inventory  
was practical, that may be more difficult on e.g. AWS.

Another way would be to break your main playbook into smaller  
sub-playbooks and explicitly  
gather the required facts at the top of them.

---

<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:** [September 26, 2015, 11:12pm UTC](https://forum.ansible.com/t/hostvars-and-limit/19360/3 "2015-09-26T23:12:13Z")

</div>

in current devel you can use delegated fact gathering:

- serup:  
&nbsp;&nbsp;delegate\_to: "{{item}}"  
&nbsp;&nbsp;with\_items: "{{groups['all']}}"
