Hi everyone
I’m new to Ansible and I’m trying to automate the generation of Cisco router configuration files.
For the same config template, I will have several hardware models and I’d like to keep the code simple.
`
#main.yml (roles tasks)
Hi everyone
I’m new to Ansible and I’m trying to automate the generation of Cisco router configuration files.
For the same config template, I will have several hardware models and I’d like to keep the code simple.
`
#main.yml (roles tasks)
"How do I access a variable name programmatically" is the correct way to do it
https://docs.ansible.com/ansible/faq.html#how-do-i-access-a-variable-name-programmatically
interface {{ hostvars[inventory_hostname][item.model]['wan'] }}
Hi
Still have an error
failed: [NRT001] (item={u’model’: u’NRT4451’, u’hostname’: u’NRT001’}) => {“failed”: true, “item”: {“hostname”: “NRT001”, “model”: “NRT4451”}, “msg”: “AnsibleUndefinedVariable: ‘dict object’ has no attribute u’NRT4451’”}
Is your variable definition in the roles vars/main.yml, if so this should work.
interface {{ vars[item.model]['wan'] }}
Have a look here.