jinja woes

I really want better fp support for collections.

With the following, where state defaults to 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?

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…