Given the following inventory and variables:
ansible-mesos:$ cat hosts
...
[zookeepers]
zk1.dom zk_id=1
zk2.dom zk_id=2
zk3.dom zk_id=3
....
nsible-mesos:$ cat group_vars/all
...
zk_client_port: 2181
mesos_cluster: democluster
.....
I want to create a one-line file that looks like:
zk://zk1.dom:2181,zk2.dom:2181,zk3.dom:2181/democluster
groups['zookeepers'] holds the list of hostnames i want, so all i really
need to do is map() each element to get a new list of
'fqdn:port' fragments and then join them with ','.
But the best I could manage in an ansible template was:
ansible-mesos:$ cat roles/mesos-common/templates/etc/mesos/zk.j2
{# clanky hack ahoy! #}
zk://{% for z in groups['zookeepers'] %}
{{ hostvars[z][service_interface].ipv4.address }}:{{ zk_client_port
}}{% if not loop.last %},{% endif %}
{% endfor %}/{{ mesos_cluster }}
ansible-mesos:$
[ i can live with it in this case but annoyingly there are several other
parts of the service configs that require the same hack and it's
getting a bit ugly
in there ]
Is there something like pythons map() I can use in templates (ideally
without requiring any Jinja add-ons)?