---
# Copyright 2016 FUJITSU LIMITED
# file: group_vars/haproxy_group

clustercheck_port: 9199

load_balancer_host: "{{ keepalived_virtual_ip }}"

mariadb_hosts: "{% for item in groups['mariadb_group'] -%}
                    {% if loop.index > 1 %},{% endif %}{{ hostvars[item]['ansible_ssh_host'] }}:{{ mysql_cluster_port | int }}
                {%- endfor %}"
mariadb_nodes: "{{ mariadb_hosts.split(',') }}"

influxdb_hosts: "{% for item in groups['influxdb_group'] -%}
                    {% if loop.index > 1 %},{% endif %}{{ hostvars[item]['ansible_ssh_host'] }}:{{ influxdb_client_cluster_port | int }}
                 {%- endfor %}"
influxdb_nodes: "{{ influxdb_hosts.split(',') }}"

# Add components to balancer configuration
balancing_components:
  - {
      name: "galera_cluster",
      load_balancing_port: "{{ mysql_port | int }}",
      balancing_algorithm: "leastconn",
      option_check: "httpchk",
      nodes: "{{ mariadb_nodes }}",
      params: [
        "port {{ clustercheck_port }}",
      ]
    }
  - {
      name: "influxdb_cluster",
      load_balancing_port: "{{ influxdb_client_port | int }}",
      balancing_algorithm: "leastconn",
      option_check: "httpchk",
      nodes: "{{ influxdb_nodes }}",
      params: [
        "port 8083"
      ]
    }
# Web gui needs to be enabled for Monasca Agent to gather
# metrics from HAProxy.
webgui_enable: true

# Logrotate configuration
logrotate_scripts:
  - name: haproxy
    path: "{{ haproxy_log_file }}"
    options:
      - daily
      - missingok
      - rotate 10
      - compress
      - delaycompress
      - notifempty
      - create 06400 {{ haproxy_user }} {{ haproxy_group }}
      - copytruncate
      - nomail
    scripts:
      postrotate: "/bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true; /bin/kill -HUP `cat /var/run/rsyslogd.pid 2> /dev/null` 2> /dev/null || true"
