Actually.. possibly_undefined_list should have thrown an undefined error 
before you ever try to access list_of_items on the second run.

On Tuesday, May 5, 2015 at 12:21:02 PM UTC-4, [email protected] wrote:
>
> 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$ 
>
>
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/a64e1eb9-d30d-40ee-948c-644e458457c0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to