# jinja woes

**URL:** <https://forum.ansible.com/t/jinja-woes/18494>\
**Category:** Ansible Project\
**Created:** [June 14, 2015, 4:56am UTC](https://forum.ansible.com/t/jinja-woes/18494 "2015-06-14T04:56:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Barry\_Kaplan](https://avatars.discourse-cdn.com/v4/letter/b/48db29/32.png) [@Barry\_Kaplan](https://forum.ansible.com/u/Barry_Kaplan)\
**Post date:** [June 14, 2015, 4:56am UTC](https://forum.ansible.com/t/jinja-woes/18494/1 "2015-06-14T04:56:08Z")

</div>

> I really want better fp support for collections.

With the following, where state defaults to enabled

> `
> 
> - role: rabbitmq  
> rabbitmq\_plugins:
> - name: rabbitmq\_management
> - name: rabbitmq\_autocluster\_consul  
> url: [https://github.com/aweber/.../rabbitmq\_autocluster\_consul-0.2.0.ez](https://github.com/aweber/.../rabbitmq_autocluster_consul-0.2.0.ez)  
> state: enabled  
> `

I want a task like:

> `
> 
> - name: Enable plugins  
> rabbitmq\_plugin:  
> names: “**{{rabbitmq\_plugins.filter(p =\> p.state is not defined or p.state == ‘enabled’).map(\_.name).join(‘,’)}}**”  
> new\_only: yes  
> state: enabled  
> with\_items: rabbitmq\_plugins
> 
> notify:
> 
> - rabbitmq restart  
> `

Where of course the expression for ‘names’ is a dream. Its seems so painful to work with collections.  
I know can create a template and use a lookup, or create a filter plugin. But it should be easier.

Any nuggets out there from the ansible gurus?

---

<div class="post-metadata">

**Author:** ![Barry\_Kaplan](https://avatars.discourse-cdn.com/v4/letter/b/48db29/32.png) [@Barry\_Kaplan](https://forum.ansible.com/u/Barry_Kaplan)\
**Post date:** [June 14, 2015, 5:16am UTC](https://forum.ansible.com/t/jinja-woes/18494/2 "2015-06-14T05:16:58Z")

</div>

So I ended up with

`  
{% for plugin in rabbitmq\_plugins if plugin.state is not defined or plugin.state == ‘enabled’ -%}  
{{plugin.name}}{% if not loop.last %}{{‘,’}}{% endif %}  
{% endfor %}

`

Not terrible, but…
