# jinja2 template with dictionary

**URL:** <https://forum.ansible.com/t/jinja2-template-with-dictionary/29605>\
**Category:** Ansible Project\
**Created:** [February 3, 2019, 10:06pm UTC](https://forum.ansible.com/t/jinja2-template-with-dictionary/29605 "2019-02-03T22:06:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ashok1](https://avatars.discourse-cdn.com/v4/letter/a/f1d935/32.png) [@Ashok1](https://forum.ansible.com/u/Ashok1)\
**Post date:** [February 3, 2019, 10:06pm UTC](https://forum.ansible.com/t/jinja2-template-with-dictionary/29605/1 "2019-02-03T22:06:47Z")

</div>

I have the following dict:

> syslog\_clients:

mailout:  
hosts: “[‘10.5.10.111’, ‘10.5.10.112’, ‘10.5.10.11’]”  
destinations:

- destination: ‘/logs/mail/mail.log’

> apache:  
> hosts: “[‘10.5.13.24’, ‘10.5.13.25’, ‘10.5.13.26’]”  
> destinations:
> 
> - var: ‘$syslogtag’  
> contains: ‘apache-access:’  
> destination: ‘/logs/web/access.log’
> - var: ‘$syslogtag’  
> contains: ‘apache-error:’  
> destination: ‘/logs/web/error.log’

Required output:

> if $fromhost-ip == [“10.5.10.111”, “10.5.10.112”, “10.5.10.11”] then /logs/mail/mail.log  
> & stop
> 
> if $fromhost-ip == [‘10.5.13.24’, ‘10.5.13.25’, ‘10.5.13.26’] then {  
> if $syslogtag contains ‘apache-access:’ then /logs/web/access.log  
> & stop  
> else if $syslogtag contains ‘apache-error:’ then /logs/web/error.log  
> & stop  
> else /logs/web/other.log  
> & stop  
> }

Above output is a Rsyslog config file. Logs from certain (like **apache** ) `syslog-clients` need to have the variable ‘$syslogtag’ evaluated, while from some (like **mailout** ) need not. I need to have a Jinja2 template that fits both the types of `syslog-clients`.

Thank you.
