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 %}
}
Written by Mark Maas
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ansible
Authors
Misha Behersky
78.97K
tartansandal
73.31K
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#