We are getting following error which is not letting us to configure or 
paste the haproxy.cfg from template file. Do we need any specific modules 
to replace with variable as we have in our playbook below?

Error:

TASK [Copying config files] 
********************************************************************************************************************************************
fatal: [172.31.22.4]: FAILED! => {"changed": true, "exit_status": 1, 
"failed": true, "msg": "failed to validate", "stderr": "[ALERT] 224/120802 
(6071) : parsing 
[/root/.ansible/tmp/ansible-tmp-1502626081.81-189349085727202/source:29] : 
server nginx1 has neither service port nor check port nor tcp_check rule 
'connect' with port information. Check has been disabled.\n[ALERT] 
224/120802 (6071) : parsing 
[/root/.ansible/tmp/ansible-tmp-1502626081.81-189349085727202/source:30] : 
server nginx2 has neither service port nor check port nor tcp_check rule 
'connect' with port information. Check has been disabled.\n[ALERT] 
224/120802 (6071) : Error(s) found in configuration file : 
/root/.ansible/tmp/ansible-tmp-1502626081.81-189349085727202/source\n[ALERT] 
224/120802 (6071) : Fatal errors found in configuration.\n", 
"stderr_lines": ["[ALERT] 224/120802 (6071) : parsing 
[/root/.ansible/tmp/ansible-tmp-1502626081.81-189349085727202/source:29] : 
server nginx1 has neither service port nor check port nor tcp_check rule 
'connect' with port information. Check has been disabled.", "[ALERT] 
224/120802 (6071) : parsing 
[/root/.ansible/tmp/ansible-tmp-1502626081.81-189349085727202/source:30] : 
server nginx2 has neither service port nor check port nor tcp_check rule 
'connect' with port information. Check has been disabled.", "[ALERT] 
224/120802 (6071) : Error(s) found in configuration file : 
/root/.ansible/tmp/ansible-tmp-1502626081.81-189349085727202/source", 
"[ALERT] 224/120802 (6071) : Fatal errors found in configuration."], 
"stdout": "", "stdout_lines": []}
        to retry, use: --limit @/etc/ansible/roles/task/lb.retry
===============================================================


yml file


   haproxy_chroot: '/var/lib/haproxy'
   haproxy_user: 'haproxy'
   haproxy_group: 'haproxy'
   haproxy_version: '1.5'

  # Frontend settings.
   haproxy_frontend_name: 'hafrontend'
   haproxy_frontend_bind_address: '*'
   haproxy_frontend_port: 80
   haproxy_frontend_mode: 'http'

  # Backend settings.

   haproxy_backend_name: 'habackend'
   haproxy_backend_mode: 'http'
   haproxy_backend_balance_method: 'roundrobin'
   haproxy_backend_httpchk: 'HEAD / HTTP/1.1\r\nHost:localhost'

  # List of backend servers.
   haproxy_backend_servers:
     - {name: nginx1, address: 172.31.25.133}
     - {name: nginx2, address: 172.31.25.145}

  tasks:
   - name: install proxy
     yum:
       name: haproxy
       state: present

   - name: enable proxy
     service:
       name: haproxy
       enabled: yes
       state: started

   - name: Copying config files
     template:
       src: /etc/ansible/roles/template/haproxy.cfg.j2
       dest: /etc/haproxy/haproxy.cfg
       backup: yes
       mode: 0644
       validate: haproxy -f %s -c -q

=================================================================================================
File:---- haproxy.cfg.j2



global
  log /dev/log  local0
  log /dev/log  local1 notice
{% if haproxy_socket != '' %}
  stats socket {{ haproxy_socket }} level admin
{% endif %}
{% if haproxy_chroot != '' %}
  chroot {{ haproxy_chroot }}
{% endif %}
  user {{ haproxy_user }}
  group {{ haproxy_group }}
  daemon
{% for global_var in haproxy_global_vars %}
  {{ global_var }}
{% endfor %}
nbcore 2
defaults
  log global
  mode  http
  option  httplog
  option  dontlognull
{% if haproxy_version == '1.4' %}
        contimeout 5000
        clitimeout 50000
        srvtimeout 50000
{% else %}
        timeout connect 5000
        timeout client 50000
        timeout server 50000
{% endif %}

frontend {{ haproxy_frontend_name }}
    bind {{ haproxy_frontend_bind_address }}:{{ haproxy_frontend_port }}
    mode {{ haproxy_frontend_mode }}
    default_backend {{ haproxy_backend_name }}

backend {{ haproxy_backend_name }}
    mode {{ haproxy_backend_mode }}
    balance {{ haproxy_backend_balance_method }}
    option forwardfor
{% if haproxy_backend_httpchk != '' %}
    option httpchk {{ haproxy_backend_httpchk }}
{% endif %}
    cookie SERVERID insert indirect
{% for backend in haproxy_backend_servers %}
    server {{ backend.name }} {{ backend.address }} cookie {{ backend.name 
}} check
{% 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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/21ec6bb7-6982-4a41-a8e5-764752e1ed2a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to