Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upNested task includes when passed a list to iterate over, receive the list passed to the outermost parent. #14325
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jimi-c
Feb 5, 2016
Member
Hi @stewartm, this is currently a limitation of using loops with includes, and is documented here: http://docs.ansible.com/ansible/playbooks_loops.html#loops-and-includes
If you have any further questions, please let us know by stopping by one of the two mailing lists, as appropriate:
- https://groups.google.com/forum/#!forum/ansible-project - for user questions, tips, and tricks
- https://groups.google.com/forum/#!forum/ansible-devel - for strategy, future planning, and questions about writing code
Because this project is very active, we're unlikely to see comments made on closed tickets, but the mailing list is a great way to ask questions, or post if you don't think this particular issue is resolved.
Thank you!
|
Hi @stewartm, this is currently a limitation of using loops with includes, and is documented here: http://docs.ansible.com/ansible/playbooks_loops.html#loops-and-includes If you have any further questions, please let us know by stopping by one of the two mailing lists, as appropriate:
Because this project is very active, we're unlikely to see comments made on closed tickets, but the mailing list is a great way to ask questions, or post if you don't think this particular issue is resolved. Thank you! |
jimi-c
closed this
Feb 5, 2016
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
stewartm
Feb 6, 2016
Hi @jimi-c. Thanks for getting back to me, however I think the issue has been misinterpreted. I have read the referenced docs and they appear to support my expectation, and contradict the actual result. The docs say:
In 2.0 you are able to use with_ loops and task includes (but not playbook includes), this adds the ability to loop over the set of tasks in one shot. There are a couple of things that you need to keep in mind, a included task that has it’s own with_ loop will overwrite the value of the special item variable. So if you want access to both the include’s item and the current task’s item you should use set_fact to create a alias to the outer one.
This (to me) implies that each included task file when passed a list to iterate over, will reset the 'item' variable in the context of the tasks it contains. As can be seen from my example code, this is not happening. Instead, the 'item' variable is set once on the outer parent, and then is not overwritten within the nested includes. This is contrary to how 'with_items' behaves for tasks other than 'include'. I have updated the parent_tasks.yml example to try and make this clearer.
stewartm
commented
Feb 6, 2016
|
Hi @jimi-c. Thanks for getting back to me, however I think the issue has been misinterpreted. I have read the referenced docs and they appear to support my expectation, and contradict the actual result. The docs say:
This (to me) implies that each included task file when passed a list to iterate over, will reset the 'item' variable in the context of the tasks it contains. As can be seen from my example code, this is not happening. Instead, the 'item' variable is set once on the outer parent, and then is not overwritten within the nested includes. This is contrary to how 'with_items' behaves for tasks other than 'include'. I have updated the parent_tasks.yml example to try and make this clearer. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
moorglade
Feb 8, 2016
FYI, I believe this is the same issue which I reported here: #14146
It seems a number of people have encountered this issue, so it either is a bug, or the documentation is unclear on this specific case.
moorglade
commented
Feb 8, 2016
|
FYI, I believe this is the same issue which I reported here: #14146 It seems a number of people have encountered this issue, so it either is a bug, or the documentation is unclear on this specific case. |
stewartm commentedFeb 5, 2016
Issue Type:
Bug Report
Ansible Version:
Also replicated with:
Ansible Configuration:
(Fact caching had been enabled but I have disabled to troublshoot this issue. Stored cache file has been deleted)
Environment:
Ansible Host = RHEL 6.4
Managed Host = RHEL 6.6
Summary:
Nested task includes when passed a list to iterate over, receive the list passed to the outermost parent.
Steps To Reproduce:
Demonstrated in the following role:
tasks/main.yml
---
tasks/parent_tasks.yml
---
tasks/child_tasks.yml
---
defaults/main.yml
---
Expected Results:
I would expect child_tasks.yml to iterate over 'child_values' and therefore the debug task should output 'child_value'
Actual Results:
I have also tested additional levels of nesting, but each level always has been passed 'parent_values' as the list to iterate ove