# limit="host\_name" breaks

**URL:** <https://forum.ansible.com/t/limit-host-name-breaks/13585>\
**Category:** Ansible Project\
**Created:** [October 1, 2013, 4:11am UTC](https://forum.ansible.com/t/limit-host-name-breaks/13585 "2013-10-01T04:11:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marc\_Trudel](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@Marc\_Trudel](https://forum.ansible.com/u/Marc_Trudel)\
**Post date:** [October 1, 2013, 4:11am UTC](https://forum.ansible.com/t/limit-host-name-breaks/13585/1 "2013-10-01T04:11:02Z")

</div>

Given that group\_name is provided, if I have the following template:

> {% for host in groups[group\_name] %}  
> {{ host }}
> 
> {{ hostvars[host] }}
> 
> {% endfor %}

And I run ansible-playbook on only a single machine of group grou\_name, I will end up with just my machine gathering facts while the other machines won’t gather facts.

I understand that this might be natural to ansible (since limit says, don’t connect to other machines), but I am curious about what would be the best practice in that regard? More specifically, this apply in my case for a setup where I need to setup the first machine of a cluster application before all other machines may join in, but that machine still need access to other node configurations.

---

<div class="post-metadata">

**Author:** ![Jurgen\_Haas2](https://avatars.discourse-cdn.com/v4/letter/j/f0a364/32.png) [@Jurgen\_Haas2](https://forum.ansible.com/u/Jurgen_Haas2)\
**Post date:** [October 1, 2013, 5:13am UTC](https://forum.ansible.com/t/limit-host-name-breaks/13585/2 "2013-10-01T05:13:17Z")

</div>

I had found myself in exactly the same situation and my approach has been the use of what I call a scope of a playbook run. Here is my main playbook:

- name: “Gather Facts”  
hosts: “{{scope}}”  
gather\_facts: true  
sudo: yes

- name: “All the other stuff”  
hosts: “{{myhosts}}:&{{scope}}”  
gather\_facts: false  
sudo: yes  
roles:

- role1

- role2

The first play gathers facts from everything within {{scope}} and from the second play onwards, the facts are available for everything else.

Calling the whole thing is like this:

ansible-playbook -i hosts mymain.yml --extra-vars=“myhosts=host1,host2 scope=all”

And of course you can play around with the variables. It works really nice for me but I curious to see other suggestions.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [October 1, 2013, 5:39am UTC](https://forum.ansible.com/t/limit-host-name-breaks/13585/3 "2013-10-01T05:39:51Z")

</div>

setup:  
delegate\_to: item  
with\_items: list of other hosts  
register: varwithotherhostfacts

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [October 1, 2013, 1:37pm UTC](https://forum.ansible.com/t/limit-host-name-breaks/13585/4 "2013-10-01T13:37:22Z")

</div>

Brian’s solution is a bit much to ask of folks, and this is why we are implementing fact caching in a future release.

However, this works easily enough too:

- hosts: all  
tasks: 

- hosts: somegroup{{additional\_rules|default(‘’)}}  
tasks:

- …

And then just pass in when you wish to use limit, “-e additional\_rules=:&some\_group”

This would allow passing the limit to only specific plays on using the CLI.
