error_on_undefined_vars doesn't work for role parameters

74 views
Skip to first unread message

jack.ma...@gmail.com

unread,
May 5, 2015, 12:21:02 PM5/5/15
to ansible...@googlegroups.com
I was going to submit this as a bug but I decided to send email first in case I'm doing something wrong.

The session below should show all required information, but let me know whether something else is needed.

ansible$ cat playbooks/test_role_with_undefined_list.yml                                                                                                      
---
- hosts: 127.0.0.1
  connection
: local

  roles
:
   
- { role: ansible_tests/debug_loop_on_list, list_of_items: '{{ possibly_undefined_list }}' }
ansible$ cat roles
/ansible_tests/debug_loop_on_list/tasks/main.yml
- name: do something in a loop
  debug
: msg="loop var is '{{ item }}'"
  with_items
: list_of_items
ansible$ ansible
-playbook -e '{ "possibly_undefined_list":[ "apple", "orange" ] }' playbooks/test_role_with_undefined_list.yml                                

PLAY
[127.0.0.1] **************************************************************

GATHERING FACTS
***************************************************************
ok
: [127.0.0.1]

TASK
: [ansible_tests/debug_loop_on_list | do something in a loop] *************
ok
: [127.0.0.1] => (item=apple) => {
   
"item": "apple",
   
"msg": "loop var is 'apple'"
}
ok
: [127.0.0.1] => (item=orange) => {
   
"item": "orange",
   
"msg": "loop var is 'orange'"
}

PLAY RECAP
********************************************************************
127.0.0.1                  : ok=2    changed=0    unreachable=0    failed=0  

ansible$ ansible
-playbook playbooks/test_role_with_undefined_list.yml                              

PLAY
[127.0.0.1] **************************************************************

GATHERING FACTS
***************************************************************
ok
: [127.0.0.1]

TASK
: [ansible_tests/debug_loop_on_list | do something in a loop] *************
ok
: [127.0.0.1] => (item=list_of_items) => {
   
"item": "list_of_items",
   
"msg": "loop var is 'list_of_items'"
}

PLAY RECAP
********************************************************************
127.0.0.1                  : ok=2    changed=0    unreachable=0    failed=0  

ansible$ cat
- >/dev/null
EXPECTED BEHAVIOR ABOVE WAS
:

Error: list_of_items is undefined.

ansible$ ansible
--version
ansible
1.8.4
  configured
module search path = None
ansible$ grep error ansible
.cfg
# by default (as of 1.3), Ansible will raise errors when attempting to dereference
#error_on_undefined_vars = False
ansible$ find roles
/ansible_tests/debug_loop_on_list/ -type f                                                                                                
roles
/ansible_tests/debug_loop_on_list/tasks/main.yml
ansible$


jack.ma...@gmail.com

unread,
May 5, 2015, 12:23:34 PM5/5/15
to ansible...@googlegroups.com
Actually.. possibly_undefined_list should have thrown an undefined error before you ever try to access list_of_items on the second run.
Reply all
Reply to author
Forward
0 new messages