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'"}*


On Saturday, October 29, 2016 at 1:46:30 AM UTC+11, Kai Stian Olstad wrote:
>
> On 28. okt. 2016 11:26, [email protected] <javascript:> wrote: 
> > 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. 
>
> "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'] }} 
>
>
> -- 
> Kai Stian Olstad 
>

-- 
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/3aabc09f-c48e-460d-ad4d-2f6b96874b70%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to