Limiting hosts when including playbooks stopped working in 1.8

307 views
Skip to first unread message

Wolfgang Ziegler

unread,
Dec 4, 2014, 4:40:15 AM12/4/14
to ansible...@googlegroups.com
Hi!

I'm using the pattern outlined at https://github.com/ansible/ansible/pull/1956 to include playbooks for a limitted group of hosts. In short:
 
 
---
 
# configure-webservers.yaml
 
- name: configure the webservers
   hosts
: webservers:&$hosts tasks: ...

 
---
 
# Configure staging server
- include: configure-webservers.yaml hosts=staging




However, this stopped working when upgrading to ansible 1.8.1. Is this a bug, or is passing variables to playbook includes like that not supported any more?

If it's not supported any more, any other suggestions on how to do this?

My use case is a rather general provising playbook - including multiple roles and possibly some custom tasks - which I want to be able to dynamically apply to some hosts from a playbook run. It shouldn't apply to "all" hosts though.

Best regards,
Wolfgang

Wolfgang Ziegler // fago

unread,
Dec 4, 2014, 5:10:36 AM12/4/14
to ansible...@googlegroups.com
I figured, the variabel replacement still works fine - but for some reason the host groups are not forwarded to the included playbook anymore. E.g., in root playbook the host is in group "mygroup", but when the included playbook runs for "mygroup" the host is not matched any more. The output is like this:

PLAY ["mygroup"] **************************************************************
skipping: no hosts matched

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/c8bdwPtR640/unsubscribe.
To unsubscribe from this group and all its topics, 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/03e0501f-ade6-4a4d-ae3a-59cc9eba118c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael DeHaan

unread,
Dec 4, 2014, 7:56:26 PM12/4/14
to ansible...@googlegroups.com
Ansible hasn't used a dollar sign for variable replacement in a long time

Try

{{ hosts }}



--
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.

Wolfgang Ziegler

unread,
Dec 5, 2014, 5:48:17 PM12/5/14
to ansible...@googlegroups.com
Sure, I've been using {{ hosts }} - I just copied the example from the old docs - sry for that. I did some more testing and think this is a bug. I reported it with a simple example playbook at https://github.com/ansible/ansible/issues/9733

Michael DeHaan

unread,
Dec 5, 2014, 11:50:17 PM12/5/14
to ansible...@googlegroups.com
Where did you define the 'my group' variable?



Wolfgang Ziegler

unread,
Dec 7, 2014, 2:32:20 PM12/7/14
to ansible...@googlegroups.com
As noted in the example over at https://github.com/ansible/ansible/issues/9733 I'm setting the host-group when including the playbook like this:

- include: test-include.yml hosts="group"

Michael DeHaan

unread,
Dec 7, 2014, 4:37:25 PM12/7/14
to ansible...@googlegroups.com
Yeah the scope is wrong on this one - You can't do that.

If it happened to work like this before, it would be an accident :)




Michael DeHaan

unread,
Dec 7, 2014, 4:38:17 PM12/7/14
to ansible...@googlegroups.com
Perhaps you meant this was a playbook level include -- which perhaps should.

Can we see the top level playbook in entirety?


Wolfgang Ziegler

unread,
Dec 16, 2014, 3:53:29 PM12/16/14
to ansible...@googlegroups.com
Yes, it's a playbook level include. It looks like the following:


---
- hosts: devserver
  sudo
: yes
  tags
: devserver, provision
  tasks
:
   
-  sometasks

- include: "../devsetup/provision.yml hosts=ci-container"

- include: ci-container.yml


Hope that helps,

thank you,
Wolfgang
Reply all
Reply to author
Forward
0 new messages