jinja2 using host facts to create playbook for haproxy back end configuration question

Hi guys,

I’m putting together a playbook for a project and i cant seem to find a way to do the following:

I was to create a ha proxy config file specifying the backends from the system facts gathered namely from the hostname and host ip gathered from the haproxy hosts specified in my hosts file.

I was this info to get collected ( which is working) and iterate over the ip and hostname inserting them into the jinja2 template file. i know how to use the looping in jinja2 but i just cant seem to find how to achieve this.

Any ideas welcome

Cheers