# Rendering the variables

**URL:** <https://forum.ansible.com/t/rendering-the-variables/28998>\
**Category:** Ansible Project\
**Created:** [November 10, 2018, 7:26am UTC](https://forum.ansible.com/t/rendering-the-variables/28998 "2018-11-10T07:26:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![BIJAY\_PARIDA](https://avatars.discourse-cdn.com/v4/letter/b/7feea3/32.png) [@BIJAY\_PARIDA](https://forum.ansible.com/u/BIJAY_PARIDA)\
**Post date:** [November 10, 2018, 7:26am UTC](https://forum.ansible.com/t/rendering-the-variables/28998/1 "2018-11-10T07:26:46Z")

</div>

I have defined the variable like below:-

input\_host\_ports:

- 4000:fluent:syslog

- 4500:json:log

- 4800:plain:debuglog

I want to get the render the variables in the jinja2 for loop like below:

tcp {  
port =\> 4000  
codec =\> fluent

type =\> syslog  
}  
tcp {  
port =\> 4500  
codec =\> json {  
charset =\> “ISO-8859-1”  
}

type =\> debuglog  
}

tcp {  
port =\> 4800  
codec =\> plain

type =\> debuglog  
}

Only for the port 4500 - I want the charset and also the output should be exactly in this format and in future I may add new ports if required.

---

<div class="post-metadata">

**Author:** ![BIJAY\_PARIDA](https://avatars.discourse-cdn.com/v4/letter/b/7feea3/32.png) [@BIJAY\_PARIDA](https://forum.ansible.com/u/BIJAY_PARIDA)\
**Post date:** [November 10, 2018, 7:27am UTC](https://forum.ansible.com/t/rendering-the-variables/28998/2 "2018-11-10T07:27:49Z")

</div>



---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [November 10, 2018, 12:17pm UTC](https://forum.ansible.com/t/rendering-the-variables/28998/3 "2018-11-10T12:17:29Z")

</div>

Start by defining your variable as a list of dicts, so you can easily  
iterate over them:

input\_host\_ports:  
&nbsp;&nbsp;- port: 4000  
&nbsp;&nbsp;&nbsp;&nbsp;codec: fluent  
&nbsp;&nbsp;&nbsp;&nbsp;type: syslog  
&nbsp;&nbsp;- port: 5500  
&nbsp;&nbsp;&nbsp;&nbsp;codec: json  
&nbsp;&nbsp;&nbsp;&nbsp;type: debuglog  
&nbsp;&nbsp;&nbsp;&nbsp;charset: ISO-8859-1  
&nbsp;&nbsp;- port: 4800  
&nbsp;&nbsp;&nbsp;&nbsp;codec: plain  
&nbsp;&nbsp;&nbsp;&nbsp;type: debuglog

Dick

---

<div class="post-metadata">

**Author:** ![BIJAY\_PARIDA](https://avatars.discourse-cdn.com/v4/letter/b/7feea3/32.png) [@BIJAY\_PARIDA](https://forum.ansible.com/u/BIJAY_PARIDA)\
**Post date:** [November 10, 2018, 7:43pm UTC](https://forum.ansible.com/t/rendering-the-variables/28998/4 "2018-11-10T19:43:36Z")

</div>

Thanks Dick, it worked.
