with_items clause with ios config module is not working

vars:
hubs: “{{groups[‘Hubs’]}}”
connection: local

tasks:

  • name: debug tasks
    debug:
    msg: “{{hostvars[item].tunnel_address}}”
    with_items: “{{ hubs }}”

  • name: test ios config
    ios_config:
    parents: interface Tunnel1
    lines:

  • description {{ hostvars[item].tunnel_address }}
    with_items: “{{ hubs }}”

Output of the playbook:
TASK [debug tasks] *************************************************************** ok: [Spoke1] => (item=Hub1) => { “changed”: false, “item”: “Hub1”, “msg”: “1.1.1.1” } ok: [Spoke1] => (item=Hub2) => { “changed”: false, “item”: “Hub2”, “msg”: “1.1.1.2” } ok: [Spoke2] => (item=Hub1) => { “changed”: false, “item”: “Hub1”, “msg”: “1.1.1.1” } ok: [Spoke2] => (item=Hub2) => { “changed”: false, “item”: “Hub2”, “msg”: “1.1.1.2” }

TASK [test ios config] ***********************************************************
fatal: [Spoke1]: FAILED! => {“msg”: “The task includes an option with an undefined variable. The error was: ‘item’ is undefined\n\nThe error appears to have been in ‘/Users/vishlpa4/central-orchestration/cso-transit-vpc-poc/configureSpokes.yml’:line 28, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: test ios config\n ^ here\n\nexception type: <class ‘ansible.errors.AnsibleUndefinedVariable’>\nexception: ‘item’ is undefined”}
fatal: [Spoke2]: FAILED! => {“msg”: “The task includes an option with an undefined variable. The error was: ‘item’ is undefined\n\nThe error appears to have been in ‘/Users/vishlpa4/central-orchestration/cso-transit-vpc-poc/configureSpokes.yml’:line 28, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: test ios config\n ^ here\n\nexception type: <class ‘ansible.errors.AnsibleUndefinedVariable’>\nexception: ‘item’ is undefined”}
to retry, use: --limit @/Users/vishlpa4/central-orchestration/cso-transit-vpc-poc/configureSpokes.retry

Any idea why this is failing ? Am I not supposed to use item in ios_config module

Found the issue.

with_items is part of task, not part of ios_config. Hence, it should align and have same indent as ios_config.

https://stackoverflow.com/questions/35270024/ansible-item-is-undefined