with_inventory_hostnames and --limit

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

limit is in there for the hosts: limitation, not for lookups, which is what
inventory_hostnames is

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

Nathan

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

+1 to delegate_to.

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

Nathan