Hey Guys, I'm a big fan of using the extract filter to get hostvar values from a set of hosts. What I have found is that I often times need to inject those vars into strings such as URLs or the such. I created a filter to allow myself to map over the list of vars and inject them into a string that I call interpolate. Just sharing in case others find it also useful.
Here is an example use case. telegraf_influxdb_urls: "{{ groups['tag_group_influxdb']|map('extract', hostvars, 'ansible_fqdn')|map('interpolate', 'http://{}:8086')|list|join(',') }}" The filter is super similar to the existing jinja2 filter called format just with the arguments flipped so that the template is applied to every element being mapped over. The source for this is just def interpolate(elem, tmpl): ''' Inject elements into a python string ''' return tmpl.format(elem) Anyways just thought I would share. If someone else knows a way to do this without having to add a new filter let me know, otherwise I think it could be a useful addition to the core ansible filters. Tony -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To post to this group, send email to ansible-project@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/6bd9cefe-ffa4-4bad-abc4-f9147a99c2de%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.