jinja woes

29 views
Skip to first unread message

Barry Kaplan

unread,
Jun 14, 2015, 12:56:08 AM6/14/15
to ansible...@googlegroups.com
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
      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? 


 


Barry Kaplan

unread,
Jun 14, 2015, 1:16:58 AM6/14/15
to ansible...@googlegroups.com
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...
Reply all
Reply to author
Forward
0 new messages