I've got a template like so:
listen {{haproxy_app_name}} 0.0.0.0:514
mode {{haproxy_mode}}
balance {{haproxy_algorithm}}
option httpclose
option forwardfor
{% for server in haproxy_backend_servers %}
server {{server.name}} {{server.ip}}:{{server.port}} {{server.paramstring}}
{% endfor %}
I'm trying to populate haproxy_backend_servers with a list of dictionaries referencing the list of hosts in inventory but am struggling with the syntax. I'm not sure if it's because of a lack of understanding of Jinja, Ansible or YAML though.
I do not have a dynamic inventory, I just have more hosts than I care to manually repeat this process for.
- hosts: balancer
vars:
haproxy_app_name: balancer
haproxy_mode: tcp
haproxy_algorithm: roundrobin
haproxy_backend_servers:
- name: listener
ip: "{{ item }}"
port: 514
paramstring: cookie A check
with_items: "{{ groups.listener }}"
Every time I try to run it it fails with FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'item' is undefined"}. (The indentation of with_items does not seem to affect the error; how it's pasted is simply where I left off.)
Is this possible to do in this context? Is there a better way?