Ansible 2.2 behaviour on includes.

63 views
Skip to first unread message

ansible...@gmail.com

unread,
Nov 1, 2016, 7:39:54 PM11/1/16
to Ansible Project
Hi,

I have one script which includes another and now with ansible 2.2 it generates a fatal error:

script 1: t.yml
---
- hosts: localhost
  connection: local
  gather_facts: no

  tasks:

    - set_fact: check_number="0"
    - include: y.yml
      when: check_number == "1"

script 2: y.yml

---
- set_fact: mymsg="Does this work"
- shell: echo "{{ item }}"
  with_items:
    - "{{ mymsg }}"

If I execute the script in ansible 2.2 it fails

$ ansible-playbook t.yml

PLAY [localhost] ***************************************************************

TASK [set_fact] ****************************************************************
ok: [localhost]

TASK [set_fact] ****************************************************************
skipping: [localhost]

TASK [command] *****************************************************************
fatal: [localhost]: FAILED! => {"failed": true, "msg": "'mymsg' is undefined"}
to retry, use: --limit @/devops/provision/ansible/t.retry

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

It always ran with previous version although with a error message

$ ansible-playbook t.yml
statically included: /Users/hrf/jelli/devops/provision/ansible/y.yml

PLAY [localhost] ***************************************************************

TASK [set_fact] ****************************************************************
ok: [localhost]

TASK [set_fact] ****************************************************************
skipping: [localhost]

TASK [command] *****************************************************************
[DEPRECATION WARNING]: Skipping task due to undefined Error, in the future this will be a fatal error.: 'mymsg' is undefined.
This feature will be removed in a future release.
Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
skipping: [localhost]

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

This was done before blocks were available.  It was my way of executing a block of code on a conditional basis.  It seems reasonable that this should work even with ansible 2.2 without being a fatal error.

Thanks,
    -Harold


James Cammarata

unread,
Nov 1, 2016, 8:16:51 PM11/1/16
to ansible...@googlegroups.com
Hi Harold, was this working on 2.1?

James Cammarata

Ansible Lead/Sr. Principal Software Engineer
Ansible by Red Hat
twitter: @thejimic, github: jimi-c

--
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-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/b2476212-0068-46c7-9e67-b321db51d94c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages