Template Module with_nested ?

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] (item=[{‘file_name’: ‘DBcreate.j2’, ‘ext’: ‘sh’}, {‘host’: ‘dmcinrfkdk17v.dmci-isf.com’, ‘specific_ip’: ‘192.168.1.46’, ‘specific_host’: ‘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”,

“ora_sid”: “Ansible”,

“specific_host”: “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’

Your template file is apparently referencing “item.ORA_SID” instead of “item[0].ora_sid”.

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