Consider I have this variable list that can contain as little as 1 and up to 4 items.
ldapservers:
server1
server2
Consider this line in my ldap.conf template.
URI ldap://{{ ldapservers(’ ') }}/
I would like the resulting file to look like this:
URI ldap://server1/ ldap://server2/
I know I can use “join” with something like this, but how do I keep the “URI” the " ldap://" and the trailing “/” consistent without adding them to the variable.
There may be more elegant ways to achieve this, but I had a similar requirement from some Eventstore config a while back and ended up with a construct like:
Construct each GossipSeed from ansible_play_hosts minus the inventory_host
{%- set seeds = %}
{%- for host in ansible_play_hosts %}
{%- if host != inventory_hostname %}
{{ seeds.append(hostvars[host][‘ansible_host’] ~ ‘:2113’) }}
{%- endif %}
{%- endfor %}
GossipSeed: {{ seeds | join(‘,’) }}
In your case you could maybe do something like (untested):
Construct list of LDAP server URIs
{%- set ldap_sever_list = %}
{%- for server in ldapservers %}
{{ ldap_sever_list.append(‘ldap://’ ~ server ~ ‘/’) }}
{%- endfor %}