for statement using dictionaries and macros in jinja2 templates with Ansible

tasks/main.yml:

- name: configure
  template:
    src: haproxy.cfg.j2
    dest: /etc/haproxy/haproxy.cfg
    owner: root
    group: root
    mode: 0644
  notify: reload haproxy
templates/backend.j2:
{% macro backend(server, ip, port=8080) -%}
    server {{ server }} {{ ip }}: {{ port }} check
{%- endmacro %}
templates/haproxy.cfg.j2:
...
{% import backend.j2 as backend %}
backend refinery
{% for server, value in haproxy_backends.items() %}
backend (server, value.ip)
{% endfor %}
...
defaults/main.yml:
...
haproxy_stats: true
haproxy_backends:
  refinery01:
    ip: 192.168.5.41
  refinery02:
    ip: 192.168.5.42
...