I have haproxy role , variables defined under vars/main.yml and template defined under template/haproxy.cfg.j2
in main.yml var file I defined this variable : iface: ansible_default_ipv4.interface
in the template file:
backend app
balance roundrobin
{% for host in groups['web'] %}
server {{ host }} {{ hostvars[host]['ansible_'+ iface ]['ipv4']['address'] }}:80 check
{% endfor %}
The problem is when I execute the playbook I get the following error : changed": false, "msg": "AnsibleUndefinedVariable: 'ansible.vars.hostvars.HostVarsVars object' has no attribute u'ansible_ansible_default_ipv4.interface'
So as I know I have problem in the concatenation ['ansible_'+iface].
Please your help.