{"action":"created","issue":{"url":"https://api.github.com/repos/ansible/ansible/issues/14146","repository_url":"https://api.github.com/repos/ansible/ansible","labels_url":"https://api.github.com/repos/ansible/ansible/issues/14146/labels{/name}","comments_url":"https://api.github.com/repos/ansible/ansible/issues/14146/comments","events_url":"https://api.github.com/repos/ansible/ansible/issues/14146/events","html_url":"https://github.com/ansible/ansible/issues/14146","id":129071300,"number":14146,"title":"Ansible 2.0.0.2: Nested include + with_items does not work properly","user":{"login":"moorglade","id":8457512,"avatar_url":"https://avatars3.githubusercontent.com/u/8457512?v=3","gravatar_id":"","url":"https://api.github.com/users/moorglade","html_url":"https://github.com/moorglade","followers_url":"https://api.github.com/users/moorglade/followers","following_url":"https://api.github.com/users/moorglade/following{/other_user}","gists_url":"https://api.github.com/users/moorglade/gists{/gist_id}","starred_url":"https://api.github.com/users/moorglade/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/moorglade/subscriptions","organizations_url":"https://api.github.com/users/moorglade/orgs","repos_url":"https://api.github.com/users/moorglade/repos","events_url":"https://api.github.com/users/moorglade/events{/privacy}","received_events_url":"https://api.github.com/users/moorglade/received_events","type":"User","site_admin":false},"labels":[{"id":48276055,"url":"https://api.github.com/repos/ansible/ansible/labels/bug_report","name":"bug_report","color":"fbca04","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/ansible/ansible/milestones/6","html_url":"https://github.com/ansible/ansible/milestone/6","labels_url":"https://api.github.com/repos/ansible/ansible/milestones/6/labels","id":995714,"number":6,"title":"stable-2.1","description":"","creator":{"login":"abadger","id":209242,"avatar_url":"https://avatars1.githubusercontent.com/u/209242?v=3","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},"open_issues":26,"closed_issues":281,"state":"open","created_at":"2015-02-25T19:26:53Z","updated_at":"2017-03-11T05:23:01Z","due_on":null,"closed_at":null},"comments":28,"created_at":"2016-01-27T08:41:39Z","updated_at":"2017-03-23T14:38:19Z","closed_at":"2016-05-12T01:53:24Z","body":"##### Issue Type:\n\nBug report\n##### Ansible Version:\n\nansible 2.0.0.2\nansible 2.1.0 (devel 7e3963420d)\n##### Ansible Configuration:\n\nN/A\n##### Environment:\n\nUbuntu 15.10\n##### Summary:\n\nAnsible 2.0 added a feature to use _include_ statements together with _with_items_ loops. When nesting _include_ statements, (i.e. file _A.yml_ includes _B.yml_, which includes _C.yml_) the _item_ variable is not set properly, i.e. the inner _include_ + _with_items_ loop does not override the _item_ value from the outer loop.\n##### Steps To Reproduce:\n\n_main.yml_\n\n``` yaml\n\n---\n- include: include_outer.yml\n  with_items:\n    - 1\n    - 2\n    - 3\n```\n\n_include_outer.yml_\n\n``` yaml\n\n---\n- debug:\n    msg: \"Outer include: item={{ item }}\"\n\n- include: include_inner.yml\n  with_items:\n    - A\n    - B\n    - C\n```\n\n_include_inner.yml_\n\n``` yaml\n\n---\n- debug:\n    msg: \"Inner include: item={{ item }}\"\n```\n##### Expected Results:\n\n```\n\"msg\": \"Outer include: item=1\"\n\"msg\": \"Inner include: item=A\"\n\"msg\": \"Inner include: item=B\"\n\"msg\": \"Inner include: item=C\"\n\"msg\": \"Outer include: item=2\"\n\"msg\": \"Inner include: item=A\"\n\"msg\": \"Inner include: item=B\"\n\"msg\": \"Inner include: item=C\"\n\"msg\": \"Outer include: item=3\"\n\"msg\": \"Inner include: item=A\"\n\"msg\": \"Inner include: item=B\"\n\"msg\": \"Inner include: item=C\"\n```\n##### Actual Results:\n\n```\n\"msg\": \"Outer include: item=1\"\n\"msg\": \"Inner include: item=1\"\n\"msg\": \"Inner include: item=1\"\n\"msg\": \"Inner include: item=1\"\n\"msg\": \"Outer include: item=2\"\n\"msg\": \"Inner include: item=2\"\n\"msg\": \"Inner include: item=2\"\n\"msg\": \"Inner include: item=2\"\n\"msg\": \"Outer include: item=3\"\n\"msg\": \"Inner include: item=3\"\n\"msg\": \"Inner include: item=3\"\n\"msg\": \"Inner include: item=3\"\n```\n"},"comment":{"url":"https://api.github.com/repos/ansible/ansible/issues/comments/288739618","html_url":"https://github.com/ansible/ansible/issues/14146#issuecomment-288739618","issue_url":"https://api.github.com/repos/ansible/ansible/issues/14146","id":288739618,"user":{"login":"arnonki","id":19374661,"avatar_url":"https://avatars2.githubusercontent.com/u/19374661?v=3","gravatar_id":"","url":"https://api.github.com/users/arnonki","html_url":"https://github.com/arnonki","followers_url":"https://api.github.com/users/arnonki/followers","following_url":"https://api.github.com/users/arnonki/following{/other_user}","gists_url":"https://api.github.com/users/arnonki/gists{/gist_id}","starred_url":"https://api.github.com/users/arnonki/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arnonki/subscriptions","organizations_url":"https://api.github.com/users/arnonki/orgs","repos_url":"https://api.github.com/users/arnonki/repos","events_url":"https://api.github.com/users/arnonki/events{/privacy}","received_events_url":"https://api.github.com/users/arnonki/received_events","type":"User","site_admin":false},"created_at":"2017-03-23T14:38:19Z","updated_at":"2017-03-23T14:38:19Z","body":"Hello, \r\n\r\nThere is definitely an issue with the include + loop functionality.\r\nUsing Ansible 2.2.0 and the following role:\r\n\r\nouter.yml:\r\n```yml\r\n- include: inner.yml outer_item=\"{{ outer_item }}\"\r\n  with_items:\r\n    - 1\r\n    - 2\r\n    - 3\r\n  loop_control:\r\n    loop_var: outer_item\r\n```\r\n\r\ninner.yml:\r\n```yml\r\n- debug: msg=\"Outer item={{outer_item}}\"\r\n```\r\n\r\nWhat I get as an output is:\r\n\r\n```\r\n\r\nPLAY [Apply customers configuration] *******************************************\r\n\r\nTASK [setup] *******************************************************************\r\nok: [localhost]\r\n\r\nTASK [test_task : include] *****************************************************\r\n [WARNING]: The loop variable 'outer_item' is already in use. You should set the `loop_var` value in the `loop_control` option for the task to something else\r\nto avoid variable collisions and unexpected behavior.\r\nincluded: /home/arnonk/playzone/roles/test_task/tasks/inner.yml for localhost\r\nincluded: /home/arnonk/playzone/roles/test_task/tasks/inner.yml for localhost\r\nincluded: /home/arnonk/playzone/roles/test_task/tasks/inner.yml for localhost\r\n\r\nTASK [test_task : debug] *******************************************************\r\n [WARNING]: The loop variable 'outer_item' is already in use. You should set the `loop_var` value in the `loop_control` option for the task to something else\r\nto avoid variable collisions and unexpected behavior.\r\nok: [localhost] => (item=None) => {\r\n    \"msg\": \"Outer item=1\", \r\n    \"outer_item\": 1\r\n}\r\nok: [localhost] => (item=None) => {\r\n    \"msg\": \"Outer item=2\", \r\n    \"outer_item\": 2\r\n}\r\nok: [localhost] => (item=None) => {\r\n    \"msg\": \"Outer item=3\", \r\n    \"outer_item\": 3\r\n}\r\n\r\nTASK [test_task : debug] *******************************************************\r\n [WARNING]: The loop variable 'outer_item' is already in use. You should set the `loop_var` value in the `loop_control` option for the task to something else\r\nto avoid variable collisions and unexpected behavior.\r\nok: [localhost] => (item=None) => {\r\n    \"msg\": \"Outer item=1\", \r\n    \"outer_item\": 1\r\n}\r\nok: [localhost] => (item=None) => {\r\n    \"msg\": \"Outer item=2\", \r\n    \"outer_item\": 2\r\n}\r\nok: [localhost] => (item=None) => {\r\n    \"msg\": \"Outer item=3\", \r\n    \"outer_item\": 3\r\n}\r\n\r\nTASK [test_task : debug] *******************************************************\r\n [WARNING]: The loop variable 'outer_item' is already in use. You should set the `loop_var` value in the `loop_control` option for the task to something else\r\nto avoid variable collisions and unexpected behavior.\r\nok: [localhost] => (item=None) => {\r\n    \"msg\": \"Outer item=1\", \r\n    \"outer_item\": 1\r\n}\r\nok: [localhost] => (item=None) => {\r\n    \"msg\": \"Outer item=2\", \r\n    \"outer_item\": 2\r\n}\r\nok: [localhost] => (item=None) => {\r\n    \"msg\": \"Outer item=3\", \r\n    \"outer_item\": 3\r\n}\r\n\r\nPLAY RECAP *********************************************************************\r\nlocalhost                  : ok=7    changed=0    unreachable=0    failed=0   \r\n```\r\n\r\nWhat is expected is to get is the following output (and behavior) \r\n\r\n```\r\n\r\nPLAY [Apply customers configuration] *******************************************\r\n\r\nTASK [setup] *******************************************************************\r\nok: [localhost]\r\n\r\nTASK [test_task : include] *****************************************************\r\n [WARNING]: The loop variable 'outer_item' is already in use. You should set the `loop_var` value in the `loop_control` option for the task to something else\r\nto avoid variable collisions and unexpected behavior.\r\nincluded: /home/arnonk/playzone/roles/test_task/tasks/inner.yml for localhost\r\nincluded: /home/arnonk/playzone/roles/test_task/tasks/inner.yml for localhost\r\nincluded: /home/arnonk/playzone/roles/test_task/tasks/inner.yml for localhost\r\n\r\nTASK [test_task : debug] *******************************************************\r\n\r\nok: [localhost] => (item=None) => {\r\n    \"msg\": \"Outer item=1\", \r\n    \"outer_item\": 1\r\n}\r\n\r\nTASK [test_task : debug] *******************************************************\r\n\r\nok: [localhost] => (item=None) => {\r\n    \"msg\": \"Outer item=2\", \r\n    \"outer_item\": 2\r\n}\r\n\r\nTASK [test_task : debug] *******************************************************\r\n\r\nok: [localhost] => (item=None) => {\r\n    \"msg\": \"Outer item=3\", \r\n    \"outer_item\": 3\r\n}\r\n\r\nPLAY RECAP *********************************************************************\r\nlocalhost                  : ok=7    changed=0    unreachable=0    failed=0   \r\n```\r\n\r\nMake sense, right ?"}}
{"actor":{"display_login":"arnonki"}}