Conditional includes and registered variables

I am having an issue where I include a playbook based on a variable. However, it seems that when the playbook is “skipped” it is still trying to evaluate my “when” statements for the tasks in that playbook. I have seen this behavior on the latest 1.2 release as well as the most recent 1.3 dev branch.

The original issue I thought was this:

https://github.com/ansible/ansible/issues/3539

But I am told this may be unrelated. This is the ‘main.yml’ and playbook I am using:

main.yml:

  • include: dbapp.yml
    when: “‘{{ role }}’ == ‘dbapp’”
  • include: webapp.yml
    when: “‘{{ role }}’ == ‘webapp’”
  • include: solr.yml
    when: “‘{{ role }}’ == ‘SOLR’”

dbapp.yml:

  • name: Check if tomcat 7 is installed
    stat: path=/opt/apache-tomcat-{{ tc_ver }}
    register: t7

  • name: Fetch tomcat 7
    s3: >
    bucket=xxxxxxxx
    object=/tomcat/apache-tomcat-{{ tc_ver }}.tar.gz
    dest=/tmp/apache-tomcat-{{ tc_ver }}.tar.gz
    mode=get
    ec2_access_key={{ aws_creds.access_key }}
    ec2_secret_key={{ aws_creds.secret_key }}
    when: t7.stat.isdir is not defined
    ignore_errors: yes

I am using this command to call it with the results:

ansible-playbook -i host, -e “role=‘webapp’” profile_test.yml

Results:
PLAY [Configure instance(s) profiles] *****************************************

GATHERING FACTS ***************************************************************
ok: [xxxxxxxxxxxxxxx]

TASK: [Check if tomcat 7 is installed] ****************************************
skipping: [xxxxxxxxxxxxxxx]

TASK: [Fetch tomcat 7] ********************************************************
fatal: [xxxxxxxxxxxxxxx] => unable to evaluate conditional: {% if t7.stat.isdir is not defined %} True {% else %} False {% endif %}

FATAL: all hosts have already failed – aborting

PLAY RECAP ********************************************************************
xxxxxxxxxxxxxxx : ok=1 changed=0 unreachable=1 failed=0

Any help/advice would be much appreciated.

Regards,
Nick

It currently does insert the item ahead of the other in 1.3, as it should, so the first test is evaluated first. So it’s not quite the same ticket.

Probably needs to actually check one and then evaluate the other rather than doing an and query though.

Since this is not quite the same thing, can you open a ticket in github?

Thanks!