Help understanding how the limit flag works with the ansible-playbook command

237 views
Skip to first unread message

Daniel Richardson

unread,
Feb 4, 2015, 7:17:06 PM2/4/15
to ansible...@googlegroups.com
I ran into what seemed to me like a strange problem today, but I might just lack the understanding to know what was happening. 
Let's say you have a YAML file called ec2.yml to run against that looks like this:

---

- hosts: tag_ansible_host1
  roles
:
     
- role1
     
- role2

- hosts: tag_ansible_host2
  roles
:
     
- role2

Both of these hosts are at ec2 and you are using the ec2 dynamic inventory script. Both hosts are also tagged with ansible:host1 and ansible:host2.
I was in a similar situation today and ran a similar command to the following:

ansible-playbook -l tag_ansible_host2 ec2.yml

What I expected to happen was that ansible would only run role2 on both hosts since I specified the limit flag. However, what happened was that ansible began running role1 and role2 on both hosts. I suspect either I am just missing something about how the limit flag works. Can anyone help me understand what I did wrong?

Brian Coca

unread,
Feb 5, 2015, 6:11:06 AM2/5/15
to ansible...@googlegroups.com
limit filters the available host list, since both hosts have the host2
tag, it does not modify the list of hosts in the play.

it reads like this once resolved

- hosts: "tag_ansible_hosts1:&tag_ansible_host2"
...

- hosts: "tag_ansible_hosts2:&tag_ansible_hosts2"

It does not limit to an existing play declaration, but imposes
additional limits to those. What you seem to want is play tags.

- hosts: tag_ansible_host1
tags:
- host1
roles:
- role1
- role2

- hosts: tag_ansible_host2
tags:
- host2
roles:
- role2


and then run ansible with -t 'host2'



--
Brian Coca

Daniel Richardson

unread,
Feb 6, 2015, 11:48:22 AM2/6/15
to ansible...@googlegroups.com
Thanks so much Brian. That makes a lot of sense now.
Reply all
Reply to author
Forward
0 new messages