# Template Module with\_nested ?

**URL:** <https://forum.ansible.com/t/template-module-with-nested/37729>\
**Category:** Ansible Project\
**Created:** [March 6, 2023, 1:12am UTC](https://forum.ansible.com/t/template-module-with-nested/37729 "2023-03-06T01:12:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Endure\_Kona](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/endure_kona/32/391_2.png) [@Endure\_Kona](https://forum.ansible.com/u/Endure_Kona)\
**Post date:** [March 6, 2023, 1:12am UTC](https://forum.ansible.com/t/template-module-with-nested/37729/1 "2023-03-06T01:12:18Z")

</div>

I have no clue why the template module fails and the shell works with the nested items. I don’t have ‘ORA\_SID’ any place but it keeps saying its ansible.errors.AnsibleUndefinedVariable, any ideas on this one would be welcome. Thanks

Plays:

- name: test running the shell - Works

ansible.builtin.shell: touch /tmp/{{ item.0.file\_name | replace(‘.j2’, ‘’) }}\_{{ item.1.ora\_sid }}.{{ item.0.ext }}

with\_nested:

- “{{ db\_create\_files }}”

- “{{ specific\_hosts\_conf }}”

when: inventory\_hostname == item.1.host

- name: test with template with nested item – DOES NOT WORK

template:

src: “{{ item.0.file\_name }}”

dest: “/tmp/{{ item.0.file\_name | replace(‘.j2’, ‘’) }}\_{{ item.1.ora\_sid }}.{{ item.0.ext }}”

with\_nested:

- “{{ db\_create\_files }}”

- “{{ specific\_hosts\_conf }}”

when: inventory\_hostname == item.1.host

Vars file:

specific\_hosts\_conf:

- { host: ‘nrfkdk17v.test.local’, specific\_ip: ‘192.168.1.46’, specific\_host: ‘nrfkdk17v.test.local nrfkdk17v’, ora\_sid: ‘Ansible’}

db\_create\_files:

- { file\_name: ‘DBcreate.j2’, ext: ‘sh’}

Error:

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible.errors.AnsibleUndefinedVariable: ‘list object’ has no attribute ‘ORA\_SID’. ‘list object’ has no attribute ‘ORA\_SID’

failed: [[dmcinrfkdk17v.dmci-isf.com](http://dmcinrfkdk17v.dmci-isf.com)] (item=[{‘file\_name’: ‘DBcreate.j2’, ‘ext’: ‘sh’}, {‘host’: ‘[dmcinrfkdk17v.dmci-isf.com](http://dmcinrfkdk17v.dmci-isf.com)’, ‘specific\_ip’: ‘192.168.1.46’, ‘specific\_host’: ‘[dmcinrfkdk17v.dmci-isf.com](http://dmcinrfkdk17v.dmci-isf.com) nrfkdk17v’, ‘ora\_sid’: ‘Ansible’}]) =\> {

“ansible\_loop\_var”: “item”,

“changed”: false,

“item”: [

{

“ext”: “sh”,

“file\_name”: “DBcreate.j2”

},

{

“host”: “[dmcinrfkdk17v.dmci-isf.com](http://dmcinrfkdk17v.dmci-isf.com)”,

“ora\_sid”: “Ansible”,

“specific\_host”: “[dmcinrfkdk17v.dmci-isf.com](http://dmcinrfkdk17v.dmci-isf.com) nrfkdk17v”,

“specific\_ip”: “192.168.1.46”

}

]

}

MSG:

AnsibleUndefinedVariable: ‘list object’ has no attribute ‘ORA\_SID’. ‘list object’ has no attribute ‘ORA\_SID’

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [March 6, 2023, 1:41am UTC](https://forum.ansible.com/t/template-module-with-nested/37729/2 "2023-03-06T01:41:11Z")

</div>

Your template file is apparently referencing “item.ORA\_SID” instead of “item[0].ora\_sid”.

---

<div class="post-metadata">

**Author:** ![Endure\_Kona](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/endure_kona/32/391_2.png) [@Endure\_Kona](https://forum.ansible.com/u/Endure_Kona)\
**Post date:** [March 6, 2023, 2:30am UTC](https://forum.ansible.com/t/template-module-with-nested/37729/3 "2023-03-06T02:30:30Z")

</div>

Ugh the one place I missed checking…thank you sir!
