Can anyone help me with the below, maybe my approach is wrong. What I’m 
trying to do is to create from a template a keepalived file based on the 
elements in a dictionary.

 

I’ve included the code below, when its ran the error that appears is 

 

                msg": "AnsibleUndefinedVariable: 'dict object' has no 
attribute 'hostname'"

 

The error appears to in the second loop in the jinja2 template, where i try 
to extract the elements from the sub lst in the dictionary.

 

ANSIBLE Dictionary 

 

keepalived_virtual_ip:

  - vip_details_1:

    haproxy_vip_name: "AddressCleaner_Development"

    ip: "1.0.1.2"

    front_end_port: 80

    haproxy_backend_servers:

       - servers_1.1:

          hostname: system12

          address: 2.0.0.1

       - servers_1.2:

          hostname: system13

          address: 2.0.0.2

 

  - vip_details_2:

    haproxy_vip_name: "AddressCleaner_Cert"

    ip: "3.0.0.114"

    front_end_port: 80

    haproxy_backend_servers:

       - servers_2.1:

          hostname: system21

          address: 2.0.0.3

       - servers_2.2:

          hostname: system22

          address: 2.0.0.4

 

 

 

keepalived_virtual_ip:

  - vip_details_1:

    haproxy_vip_name: "AddressCleaner_Development"

    ip: "3.0.0.115"

    front_end_port: 80

    haproxy_backend_servers:

       - servers_1.1:

          hostname: lonldpostal01

          address: 3.0.0.87

       - servers_1.2:

          hostname: lonldpostal02

          address: 3.0.0.100

 

  - vip_details_2:

    haproxy_vip_name: "AddressCleaner_Cert"

    ip: "3.0.0.114"

    front_end_port: 80

    haproxy_backend_servers:

       - servers_2.1:

          hostname: lonlcpostal01

          address: 3.0.0.96

       - servers_2.2:

          hostname: lonlcpostal02

          address: 3.0.0.104

 

 

 

 

HA PROXY TEMPLATE 

 

 

{% for item in keepalived_virtual_ip %}

 

   listen {{ item.haproxy_vip_name }} {{ item.ip }}:{{ item.front_end_port 
}}

      mode {{ haproxy_mode }}

      balance {{ haproxy_vip_algo }}

   default_backend {{ item.haproxy_vip_name }}_backend

 

{% endfor %}

 

 

 

{% for item in keepalived_virtual_ip %}

backend {{ item.haproxy_vip_name }}_backend

    mode tcp

    balance source

 

    {% for backend in item.haproxy_backend_servers %}

       server {{ backend.hostname }} {{ backend.address }}:{{ 
haproxy_vip_port }} maxconn 9000 send-proxy check

    {% endfor %}

 

{% endfor %}
  

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/6c315659-e24d-42b4-a4f4-918e12b7067c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to