limit now working as expected with multiple host sections

44 views
Skip to first unread message

Matt Schurenko

unread,
Sep 11, 2014, 12:01:08 AM9/11/14
to ansible...@googlegroups.com
Is this the correct behavior of using --limit:

{
$ cat test_inv
[localhost]
localhost

[foobar]
localhost

$ cat test.yml
---
- hosts:
    - localhost
  connection: local
  gather_facts: no
  tasks:
    - name: localhost
      debug: msg=localhost

- hosts:
    - foobar
  connection: local
  gather_facts: no
  tasks:
    - name: foobar
      debug: msg=foobar

$ ansible-playbook -i test_inv test.yml --list-hosts --limit foobar

playbook: test.yml

  play #1 (localhost): host count=1
    localhost

  play #2 (foobar): host count=1
    localhost
}

I thought that by using "--limit foobar" that it would only match the foobar host group? Even if "--limit" can only work on one host section in a play isn't this still a bug or something? 

BTW my ansible version is 1.8

Thanks

Michael DeHaan

unread,
Sep 11, 2014, 10:29:55 AM9/11/14
to ansible...@googlegroups.com
The short answer is:  maybe, but it's probably more important that it's considered a feature.

Often in configuring sets of machines, needing to run things locally is required to do some steps once and then apply them to a batch.

Thus, almost never do you treat the control machine as "one of the regular nodes".  For instance, if configuring webservers, you do not run ansible *from* one of the webservers, so the behavior of the localhost in that play should be innocous relative to the hosts being configured.

I think removing this would break some rather fundamental use cases with --limit.

I do understand it's common to run configuration against localhost in development or for testing, and in this case I'd recommend splitting inventories.




--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/580ecdd7-4145-4b4b-a979-085a4527a29e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages