playbook conditional include another playbook not wokring

859 views
Skip to first unread message

jack

unread,
Nov 4, 2014, 12:59:59 PM11/4/14
to ansible...@googlegroups.com
I have problem at conditional include playbook:

For example, I am following three simple playbooks:

playbook0.yml:
---
- hosts: test-servers
  tasks:

  - debug: msg="incude playbook0.yml"

playboo1.yml:
---
- hosts: test-servers
  tasks:

  - debug: msg="incude playbook1.yml"

playbook.yml:
---

- include: playbook0.yml
  when: run0 == 'true'

- include: playbook1.yml
  when: run1 == 'true'

I try to run my playbook:
ansible-playbook -i hosts playbook.yml --extra-vars="run1=true run0=false"

But it looks like the condition is not working. playbook0 and playbook1 are always included no matter what condition I set. What I did wrong? Is it possible to include another playbook conditionally?

Thanks
Jack

Brian Coca

unread,
Nov 4, 2014, 1:02:06 PM11/4/14
to ansible...@googlegroups.com

Conditions on include don't apply to the include itself, it is applied to the tasks included

--
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/5e7cb3ae-0ba5-4e5b-8b7d-ceae56abad8e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jack

unread,
Nov 4, 2014, 1:14:09 PM11/4/14
to ansible...@googlegroups.com
Thanks Brian.

if condition is apply to the tasks level, the we will expect the task  - debug: msg="incude playbook0.yml" at playbook0.yml should be skipped, but actually it is not.

Here is result:

$ ansible-playbook -i hosts playbook.yml --extra-vars="run1=true run0=false"

PLAY [test-servers] ***********************************************************

GATHERING FACTS ***************************************************************
ok: [testserver]

TASK: [debug msg="incude playbook0.yml"] **************************************
ok: [testserver] => {
    "msg": "incude playbook0.yml"
}

PLAY [test-servers] ***********************************************************

GATHERING FACTS ***************************************************************
ok: [testserver]

TASK: [debug msg="incude playbook1.yml"] **************************************
ok: [testserver] => {
    "msg": "incude playbook1.yml"
}

PLAY RECAP ********************************************************************
testserver             : ok=4    changed=0    unreachable=0    failed=0

Thanks
Jack

Michael DeHaan

unread,
Nov 4, 2014, 4:03:58 PM11/4/14
to ansible...@googlegroups.com
For starters, what ansible version are you using?



jack

unread,
Nov 4, 2014, 5:37:49 PM11/4/14
to ansible...@googlegroups.com
ansible 1.5.5 on Mac.


Michael DeHaan

unread,
Nov 5, 2014, 9:14:56 AM11/5/14
to ansible...@googlegroups.com
Please upgrade to the recent 1.7.2 and see if you have any problems.

We cannot support older versions on this list.



On Tue, Nov 4, 2014 at 5:37 PM, jack <jackm...@gmail.com> wrote:
ansible 1.5.5 on Mac.


--
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.
Reply all
Reply to author
Forward
0 new messages