# Can't Reference Array Variables

**URL:** <https://forum.ansible.com/t/cant-reference-array-variables/20406>\
**Category:** Ansible Project\
**Created:** [February 1, 2016, 5:27pm UTC](https://forum.ansible.com/t/cant-reference-array-variables/20406 "2016-02-01T17:27:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jordantkj](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jordantkj](https://forum.ansible.com/u/jordantkj)\
**Post date:** [February 1, 2016, 5:27pm UTC](https://forum.ansible.com/t/cant-reference-array-variables/20406/1 "2016-02-01T17:27:15Z")

</div>

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
