# with\_inventory\_hostnames and --limit

**URL:** <https://forum.ansible.com/t/with-inventory-hostnames-and-limit/13801>\
**Category:** Ansible Project\
**Created:** [October 29, 2013, 10:13pm UTC](https://forum.ansible.com/t/with-inventory-hostnames-and-limit/13801 "2013-10-29T22:13:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nathan\_Howell](https://avatars.discourse-cdn.com/v4/letter/n/65b543/32.png) [@Nathan\_Howell](https://forum.ansible.com/u/Nathan_Howell)\
**Post date:** [October 29, 2013, 10:13pm UTC](https://forum.ansible.com/t/with-inventory-hostnames-and-limit/13801/1 "2013-10-29T22:13:38Z")

</div>

I’ve recently discovered with\_inventory\_hostnames, which seems like exactly what I need, but --limit doesn’t seem to affect it. A quick look at the code seems to tell me that it should work, but I’m not 100% sure. I’m using it in a play like this:

- name: Deploy  
hosts: source\_server  
tasks:

- name: Copy files to servers  
command: rsync -az /files/ {{ item }}:/files  
with\_inventory\_hostnames: target\_servers

In this case, target\_servers is a group that contains 10.5.4.3 and 10.5.4.4. I run ansible-playbook with --limit 10.5.4.3, and the task runs for 10.5.4.4 as well. I’m using a recent ansible dev version (afa781d). Any ideas? Am I missing something? Thanks,

Nathan

---

<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 29, 2013, 10:22pm UTC](https://forum.ansible.com/t/with-inventory-hostnames-and-limit/13801/2 "2013-10-29T22:22:39Z")

</div>

limit is in there for the hosts: limitation, not for lookups, which is what  
inventory\_hostnames is

---

<div class="post-metadata">

**Author:** ![Nathan\_Howell](https://avatars.discourse-cdn.com/v4/letter/n/65b543/32.png) [@Nathan\_Howell](https://forum.ansible.com/u/Nathan_Howell)\
**Post date:** [October 29, 2013, 10:32pm UTC](https://forum.ansible.com/t/with-inventory-hostnames-and-limit/13801/3 "2013-10-29T22:32:03Z")

</div>

Ok, that makes sense. Is there any way to make use of the limit parameter in a task?

Nathan

---

<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 30, 2013, 12:01am UTC](https://forum.ansible.com/t/with-inventory-hostnames-and-limit/13801/4 "2013-10-30T00:01:53Z")

</div>

Answering your question, no.

Answering your need I did a minor rewrite to your play:

- name: Deploy  
hosts: target\_servers  
tasks:
- name: Copy files to servers  
command: rsync -az /files/ {{ inventory\_hostname }}:/files  
delegate\_to: source\_server

this will now work with --limit as you wish it

---

<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 30, 2013, 2:03am UTC](https://forum.ansible.com/t/with-inventory-hostnames-and-limit/13801/5 "2013-10-30T02:03:51Z")

</div>

+1 to delegate\_to.

---

<div class="post-metadata">

**Author:** ![Nathan\_Howell](https://avatars.discourse-cdn.com/v4/letter/n/65b543/32.png) [@Nathan\_Howell](https://forum.ansible.com/u/Nathan_Howell)\
**Post date:** [October 30, 2013, 3:11am UTC](https://forum.ansible.com/t/with-inventory-hostnames-and-limit/13801/6 "2013-10-30T03:11:43Z")

</div>

That’s perfect, thank you very much. I (obviously) hadn’t thought of flipping it around like that. Very cool.

Nathan
