Hi,
I am trying to reference elements in the “from” array from using the following Jinja2 structure. What I want to do is create a separate line for each of the “from” terms.
firewall:
filters:
- name: protect-re
family: inet
terms:
- name: accept-ospf
from:
- source-prefix-list router-ipv4
- destination-prefix-list router-ipv4
- destination-prefix-list ospf
then:
- count accept-ospf
- accept
apply_flags: omit
- name: accept-vrrp
from:
- source-prefix-list router-ipv4
- destination-prefix-list vrrp
- protocol vrrp
- protocol ah
then:
- count accept-vrrp
- accept
apply_flags: omit
This is the Jinja2 code that I’m using to get these variables. It works for printing each individual “name” and “apply-flags” var, but I can’t seem to get the format correct to reference the “from” array elements.
` {# FIREWALL FILTERS #} {% for myfilter in firewall.filters %} {% for myterm in myfilter.terms %} {% set prefx = 'set firewall family ' + myfilter.family + ' filter ' + myfilter.name + ' term ' + myterm.name %} {% for myfrom in myterm.from %} {{ prefx }} from {{ myfrom }} {% endfor %} {% endfor %} {% endfor %} `I get the following error when I try to create the playbook…
` TASK: [common_firewall | Building common_firewall configuration] ************** fatal: [mdf3A.site_LNG] => {'msg': "AnsibleUndefinedVariable: One or more undefined variables: 'dict object' has no attribute 'from'", 'failed': True} fatal: [mdf3A.site_LNG] => {'msg': "AnsibleUndefinedVariable: One or more undefined variables: 'dict object' has no attribute 'from'", 'failed': True}FATAL: all hosts have already failed – aborting
`
I’m sure there’s something wrong with my Jinja2 code, but can’t figure out what it is.
Thanks,
-Tyler