Last Updated: February 25, 2016
·
425
· markmaas

Including all hosts in the play but not the current host in a template

So sometimes, you need to create a config file (Like for lsyncd) that points to other hosts, but must not include the current host.

Plus, the last line of that loop must not contain a "," or ";" or whatever that language wants.

-- List of targets
targetlist = {
{% for host in play_hosts if hostvars[host]['ansible_hostname'] != ansible_hostname %}
  "{{ hostvars[host]['ansible_hostname'] }}:{{ lsyncd_dest_drive }}/"{% if not loop.last %},
{% endif %}
{% endfor %}
}