Issue 1:
ISSUE TYPE

Bug Report

COMPONENT NAME

include task

ANSIBLE VERSION

[vagrant@localhost ~]$ ansible --version
ansible 2.1.1.0
config file = /etc/ansible/ansible.cfg
configured module search path = Default w/o overrides

CONFIGURATION

No changes

OS / ENVIRONMENT

Centos 7.2

SUMMARY

the nested include task fails with "'item' is undefined" error when outer include task uses a loop

STEPS TO REPRODUCE

create a directory structure and place yml files as described in the gist below

run the ansible-playbook to hit the error

https://gist.github.com/mapuri/b4b74e81c531eedb834c5ba81cde449f

EXPECTED RESULTS

There shall be no error and the nested includes should work. This was working with ansible 2.1.0.0

ACTUAL RESULTS

[vagrant@localhost ~]$ ansible-playbook -i ./hosts ./tmp/site.yml -kK
SSH password:
SUDO password[defaults to SSH password]:

PLAY [all] *********************************************************************

TASK [setup] *******************************************************************
ok: [localhost]

TASK [include] *****************************************************************
fatal: [localhost]: FAILED! => {"failed": true, "reason": "'item' is undefined"}

NO MORE HOSTS LEFT *************************************************************
to retry, use: --limit @./tmp/site.retry

PLAY RECAP *********************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=1

Issue 2:
ISSUE TYPE

Bug Report

ANSIBLE VERSION

ansible 2.1.1.0

CONFIGURATION

None

OS / ENVIRONMENT

N/A

SUMMARY

Variables do not resolve and error out as undefined when using include statements in tasks. When you replace the below code for /duck/main.yml with anything but 'include' statements, it works fine. I have verified that this is not an issue in 2.1.0.

STEPS TO REPRODUCE

tasks/main.yml

---

- set_fact:
folder_name: 'duck'

- debug:
var: folder_name

- include: "{{ folder_name }}/main.yml"

tasks/duck/main.yml

---
- include: test.yml

tasks/duck/test.yml

---
- debug:
msg: "I made it here!"

EXPECTED RESULTS

PLAY [Set Facts Issue] *********************************************************

TASK [setup] *******************************************************************
ok: [localhost]

TASK [foo : set_fact] **********************************************************
task path: ansible/roles/foo/tasks/main.yml:3
ok: [localhost] => {"ansible_facts": {"folder_name": "duck"}, "changed": false, "invocation": {"module_args": {"folder_name": "duck"}, "module_name": "set_fact"}}

TASK [foo : debug] *************************************************************
task path: ansible/roles/foo/tasks/main.yml:6
ok: [localhost] => {
"folder_name": "duck"
}

TASK [foo : include] ***********************************************************
task path: ansible/roles/foo/tasks/main.yml:8
included: ansible/roles/foo/tasks/duck/main.yml for localhost

TASK [foo : include] ***********************************************************
task path: ansible/roles/foo/tasks/duck/main.yml:2
included: ansible/roles/foo/tasks/duck/test.yml for localhost

TASK [foo : debug] *************************************************************
task path: ansible/roles/foo/tasks/duck/test.yml:2
ok: [localhost] => {
"msg": "I made it here!"
}

PLAY RECAP *********************************************************************
localhost : ok=6 changed=0 unreachable=0 failed=0

ACTUAL RESULTS

PLAY [Set Facts Issue] *********************************************************

TASK [setup] *******************************************************************
ok: [localhost]

TASK [foo : set_fact] **********************************************************
task path: ansible/roles/foo/tasks/main.yml:3
ok: [localhost] => {"ansible_facts": {"folder_name": "duck"}, "changed": false, "invocation": {"module_args": {"folder_name": "duck"}, "module_name": "set_fact"}}

TASK [foo : debug] *************************************************************
task path: ansible/roles/foo/tasks/main.yml:6
ok: [localhost] => {
"folder_name": "duck"
}

TASK [foo : include] ***********************************************************
task path: ansible/roles/foo/tasks/main.yml:8
fatal: [localhost]: FAILED! => {"failed": true, "reason": "'folder_name' is undefined"}

PLAY RECAP *********************************************************************
localhost : ok=3 changed=0 unreachable=0 failed=1