Conditional and include

24 views
Skip to first unread message

John Oliver

unread,
Nov 19, 2014, 12:39:52 PM11/19/14
to ansible...@googlegroups.com
My playbook:

  - name: Get Java version
    shell: /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java -version 2>&1 | grep '^java' | cut -d'"' -f2
    register: jre_ver
  - debug: msg="{{ jre_ver.stdout }}"

  - name: Install JRE 8 if necessary
    include: jre8.yml
    when: jre_ver.stdout != '1.8.0_25'
    ignore_errors: true


Result:

GATHERING FACTS *************************************************************** 
ok: [eisbock]

TASK: [Get Java version] ****************************************************** 
changed: [eisbock]

TASK: [debug msg="{{ jre_ver.stdout }}"] ************************************** 
ok: [eisbock] => {
    "msg": "1.8.0_25"
}

TASK: [Copy JRE 8 installer] ************************************************** 
skipping: [eisbock]

TASK: [Mount disk image] ****************************************************** 
skipping: [eisbock]

TASK: [Dismount installer] **************************************************** 
skipping: [eisbock]

TASK: [Clean up dmg] ********************************************************** 
skipping: [eisbock]

PLAY RECAP ******************************************************************** 
eisbock                    : ok=3    changed=1    unreachable=0    failed=0


Why is ansible still including jre8.yml and skipping each step?  I thought it would just not even tough it if the conditional didn't match.

Michael Peters

unread,
Nov 19, 2014, 12:50:51 PM11/19/14
to ansible...@googlegroups.com
When you put a conditional on an include ansible adds that conditional
to each task in the include. So this is the expected behavior.
> --
> 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/a6adcff7-b9b2-4fc7-8266-4c9705489557%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages