4 ms·
I agree that your problem is much harder than it should be and I think it is due to the format() filter not being fit for use in map(). Nevertheless here are 3
by rmetzler 8y ago
I agree that your problem is much harder than it should be and I think it is due to the format() filter not being fit for use in map().
Nevertheless here are 3 versions how you could solve this problem in Jinja2:
{{ list | map('regex_replace', '(.*)', '\\1:443') | join(',') }}
{{ list | zip_longest([], fillvalue='443') | map('join', ':') | join(',') }}
{% for item in list %}{{item}}:443{%- if not loop.last %},{%- endif %}{%- endfor %}
I wish the following would be possible:
{{ list | map('format', '%s:443') | join(',') }}
- VectorLock 8y agoI ended up using a custom plugin to make it easier. The actual real world attempt was more complicated and had a crappier version of Ansible. I also wish the map/format one worked.
- mpdehaan2 8y agoMy historical argument was always that if a playbook looks ugly, it is wrong. Over the years I haven't been around to keep saying that, but I'd be inclined to have to find ways to open up the programming model while still keeping the mostly organized guide-rails in place.