{"action":"created","issue":{"url":"https://api.github.com/repos/ansible/ansible/issues/49592","repository_url":"https://api.github.com/repos/ansible/ansible","labels_url":"https://api.github.com/repos/ansible/ansible/issues/49592/labels{/name}","comments_url":"https://api.github.com/repos/ansible/ansible/issues/49592/comments","events_url":"https://api.github.com/repos/ansible/ansible/issues/49592/events","html_url":"https://github.com/ansible/ansible/issues/49592","id":388131185,"node_id":"MDU6SXNzdWUzODgxMzExODU=","number":49592,"title":"Loop vs. with_items with undefined list entries","user":{"login":"jfinkhaeuser","id":203885,"node_id":"MDQ6VXNlcjIwMzg4NQ==","avatar_url":"https://avatars3.githubusercontent.com/u/203885?v=4","gravatar_id":"","url":"https://api.github.com/users/jfinkhaeuser","html_url":"https://github.com/jfinkhaeuser","followers_url":"https://api.github.com/users/jfinkhaeuser/followers","following_url":"https://api.github.com/users/jfinkhaeuser/following{/other_user}","gists_url":"https://api.github.com/users/jfinkhaeuser/gists{/gist_id}","starred_url":"https://api.github.com/users/jfinkhaeuser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jfinkhaeuser/subscriptions","organizations_url":"https://api.github.com/users/jfinkhaeuser/orgs","repos_url":"https://api.github.com/users/jfinkhaeuser/repos","events_url":"https://api.github.com/users/jfinkhaeuser/events{/privacy}","received_events_url":"https://api.github.com/users/jfinkhaeuser/received_events","type":"User","site_admin":false},"labels":[{"id":1126594180,"node_id":"MDU6TGFiZWwxMTI2NTk0MTgw","url":"https://api.github.com/repos/ansible/ansible/labels/P3","name":"P3","color":"e3ed5e","default":false},{"id":947190508,"node_id":"MDU6TGFiZWw5NDcxOTA1MDg=","url":"https://api.github.com/repos/ansible/ansible/labels/affects_2.7","name":"affects_2.7","color":"ededed","default":false},{"id":785271699,"node_id":"MDU6TGFiZWw3ODUyNzE2OTk=","url":"https://api.github.com/repos/ansible/ansible/labels/bug","name":"bug","color":"fbca04","default":true},{"id":1130170305,"node_id":"MDU6TGFiZWwxMTMwMTcwMzA1","url":"https://api.github.com/repos/ansible/ansible/labels/needs_verified","name":"needs_verified","color":"d93f0b","default":false},{"id":383076471,"node_id":"MDU6TGFiZWwzODMwNzY0NzE=","url":"https://api.github.com/repos/ansible/ansible/labels/python3","name":"python3","color":"fbca04","default":false},{"id":636352796,"node_id":"MDU6TGFiZWw2MzYzNTI3OTY=","url":"https://api.github.com/repos/ansible/ansible/labels/support:core","name":"support:core","color":"ededed","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-12-06T09:43:26Z","updated_at":"2018-12-11T20:22:05Z","closed_at":null,"author_association":"NONE","body":"##### SUMMARY\r\nPrevious behaviour: the task would skip `Undefined` entries, and execute 0 to 2 times.\r\n```yaml\r\n- name: ...\r\n  with_items: \"{{ [variable1, variable2 ] }}\"\r\n```\r\n\r\nCurrent behaviour: the task errors out claiming that [Undefined, Undefined] (with 2 undefined items) is not a list.\r\n```yaml\r\n- name: ...\r\n  loop: \"{{ [variable1, variable2 ] }}\"\r\n```\r\n\r\nWorse, this evaluation seems to happen before `when`; the same error occurs:\r\nnot a list.\r\n```yaml\r\n- name: ...\r\n  loop: \"{{ [variable1, variable2 ] }}\"\r\n  when: variable1 is defined or variable2 is defined\r\n```\r\n\r\n##### ISSUE TYPE\r\n- Bug Report\r\n\r\n##### COMPONENT NAME\r\nCore? I don't know.\r\n\r\n##### ANSIBLE VERSION\r\n```paste below\r\nansible 2.7.4\r\n  config file = /home/<redacted>/ansible.cfg\r\n  configured module search path = ['/home/<redacted>/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']\r\n  ansible python module location = /usr/local/lib/python3.6/dist-packages/ansible\r\n  executable location = /usr/local/bin/ansible\r\n  python version = 3.6.7 (default, Oct 22 2018, 11:32:17) [GCC 8.2.0]\r\n```\r\n##### STEPS TO REPRODUCE\r\nSee above.\r\n\r\n##### EXPECTED RESULTS\r\nI'd expect the same behaviour as `with_items` produces - it makes writing tasks a ton simpler. Worst case, I'd expect `when` to be evaluated before the `loop` variable gets validated."},"comment":{"url":"https://api.github.com/repos/ansible/ansible/issues/comments/446348290","html_url":"https://github.com/ansible/ansible/issues/49592#issuecomment-446348290","issue_url":"https://api.github.com/repos/ansible/ansible/issues/49592","id":446348290,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0NjM0ODI5MA==","user":{"login":"abadger","id":209242,"node_id":"MDQ6VXNlcjIwOTI0Mg==","avatar_url":"https://avatars2.githubusercontent.com/u/209242?v=4","gravatar_id":"","url":"https://api.github.com/users/abadger","html_url":"https://github.com/abadger","followers_url":"https://api.github.com/users/abadger/followers","following_url":"https://api.github.com/users/abadger/following{/other_user}","gists_url":"https://api.github.com/users/abadger/gists{/gist_id}","starred_url":"https://api.github.com/users/abadger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abadger/subscriptions","organizations_url":"https://api.github.com/users/abadger/orgs","repos_url":"https://api.github.com/users/abadger/repos","events_url":"https://api.github.com/users/abadger/events{/privacy}","received_events_url":"https://api.github.com/users/abadger/received_events","type":"User","site_admin":false},"created_at":"2018-12-11T20:22:05Z","updated_at":"2018-12-11T20:22:05Z","author_association":"MEMBER","body":"Verified the current behaviour matches report.\r\n```\r\n---\r\n- hosts: localhost\r\n  gather_facts: False\r\n  vars:\r\n    test: test\r\n\r\n  tasks:\r\n  - debug: msg='{{ item }}'\r\n    with_items: '{{ [ test, var2 ] }}'\r\n    when: var2 is defined\r\n  - debug: msg='{{ item }}'\r\n    with_items: '{{ [ test, var2 ] }}'\r\n\r\n  - debug: msg='{{ item }}'\r\n    loop: '{{ [ test, var2 ] }}'\r\n    when: var2 is defined\r\n    ignore_errors: True\r\n\r\n  - debug: msg='{{ item }}'\r\n    loop: '{{ [ test, var2 ] }}'\r\n\r\n```\r\n```\r\n[pts/1@peru /srv/ansible/users/alikins]$ ANSIBLE_NOCOWS=1 ansible-playbook test.yml\r\n [WARNING]: No inventory was parsed, only implicit localhost is available\r\n\r\n [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not\r\nmatch 'all'\r\n\r\n\r\nPLAY [localhost] ****************************************************************************************************\r\n\r\nTASK [debug] ********************************************************************************************************\r\nskipping: [localhost] => (item=[u'test', Undefined]) \r\nskipping: [localhost]\r\n\r\nTASK [debug] ********************************************************************************************************\r\nok: [localhost] => (item=[u'test', Undefined]) => {\r\n    \"msg\": \"[u'test', Undefined]\"\r\n}\r\n\r\nTASK [debug] ********************************************************************************************************\r\nfatal: [localhost]: FAILED! => {\"msg\": \"Invalid data passed to 'loop', it requires a list, got this instead: [u'test', Undefined]. Hint: If you passed a list/dict of just one element, try adding wantlist=True to your lookup invocation or use q/query instead of lookup.\"}\r\n...ignoring\r\n\r\nTASK [debug] ********************************************************************************************************\r\nfatal: [localhost]: FAILED! => {\"msg\": \"Invalid data passed to 'loop', it requires a list, got this instead: [u'test', Undefined]. Hint: If you passed a list/dict of just one element, try adding wantlist=True to your lookup invocation or use q/query instead of lookup.\"}\r\n        to retry, use: --limit @/srv/ansible/users/alikins/test.retry\r\n\r\nPLAY RECAP **********************************************************************************************************\r\nlocalhost                  : ok=2    changed=0    unreachable=0    failed=1    skipped=1 \r\n```\r\n\r\n@bcoca and @jimi-c to resolve whether the with_items behaviour is a bug or the loop behaviour is a bug."}}
{"actor":{"display_login":"abadger"}}