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)
---
- name: Generate configuration files
template: src=CE-base.j2 dest=/home/bonh/ansible/playbooks/configs/{{item.
hostname}}.txt
with_items: "{{ CE }}"
#main.yml (variable definition)
---
CE:
- { hostname: NRT001, model: NRT4451 }
- { hostname: NRT002, model: NRT2921 }
NRT4451:
wan: GigabitEthernet0/0/1
b2b: GigabitEthernet0/0/2
lan: GigabitEthernet0/0/0
NRT2921:
wan: GigabitEthernet0/1
b2b: GigabitEthernet0/2
lan: GigabitEthernet0/0
#CE-base.j2 (base template)
---
interface {{ [item.model].wan }}
The desired result is to have the following
#NRT001.txt
interface GigabitEthernet0/0/1
#NRT002.txt
interface GigabitEthernet0/1
However I'm getting an error.
*failed: [NRT001] (item={u'model': u'NRT4451', u'hostname': u'NRT001'}) =>
{"failed": true, "item": {"hostname": "NRT001", "model": "NRT4451"}, "msg":
"AnsibleUndefinedVariable: 'list object' has no attribute 'wan'"}*
I'm not a hardcore devOps and still learning.
I tried the approach "How do I access a variable name programmatically?"
in http://docs.ansible.com/ansible/faq.html but no success.
I think that's because my item has not a 'wan' object.
Of course if I use interface {{ NRT4451.wan }} it works fine.
Can someone help? I'm hoping it's just a syntax mistake.
Thanks
Bonh
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/a0d118b8-58f5-433e-942c-7ca48440eb04%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.