No description
  • Jinja 50.3%
  • Python 49.7%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Adrien Waksberg da9fa7d6ef
All checks were successful
/ lint (push) Successful in 7s
/ molecule (push) Successful in 1m20s
feat: add official repository
2026-10-20 21:56:37 +02:00
.forgejo/workflows chore: add quote for all string in yaml 2025-05-24 11:48:42 +02:00
defaults feat: add official repository 2026-10-20 21:56:37 +02:00
handlers chore: add quote for all string in yaml 2025-05-24 11:48:42 +02:00
meta test: remove support debian 12 2026-07-20 15:34:47 +02:00
molecule/default feat: add official repository 2026-10-20 21:56:37 +02:00
tasks feat: add official repository 2026-10-20 21:56:37 +02:00
templates feat: remove default config for listen stats 2026-10-20 21:56:37 +02:00
.gitignore test: update yamllint config 2025-05-25 08:55:57 +02:00
.gitlab-ci.yml chore: add quote for all string in yaml 2025-05-24 11:48:42 +02:00
.yamllint test: update yamllint config 2025-05-25 08:55:57 +02:00
CHANGELOG.md break: remove dict for bind parameter 2026-10-20 21:56:37 +02:00
LICENSE first version 2019-11-08 22:29:11 +01:00
README.md feat: add official repository 2026-10-20 21:56:37 +02:00

Ansible role: Haproxy

Version License Build

Install and configure haproxy

Requirements

  • Ansible >= 2.21
  • Debian
    • Trixie

Role variables

Name Type Required Default Comment
haproxy_use_official_repository bool no false if true, use haproxy official repository
haproxy_version str no 3.4 when you use official repository, you can set the major version to install
haproxy_apt_release str no ansible_facts.distribution_release set the apt release to use  
haproxy_global dict no global section in configuration of haproxy 
haproxy_defaults dict no defaults sections in configuration of haproxy 
haproxy_listen_stats dict no config for listen stats section 
haproxy_resolvers dict no config the resolvers 
haproxy_frontends dict no frontends configuration 
haproxy_backends dict no backend configuration 
haproxy_subnets_lists dict no IPs list for use in haproxy ACL 
haproxy_userlists dict no user list for basic auth 
haproxy_ssl_certificates dict no SSL certificates file to copy 
haproxy_http_errors dict no HTTP error groups 
haproxy_http_errors_files dict no HTTP error files to copy 

haproxy_global

Set parameters in global section of Haproxy configuration. See all parameters in Haproxy documentation

log-send-hostname: true
chroot: /var/lib/haproxy
pidfile: /var/run/haproxy.pid
maxconn: 4096
user: haproxy
group: haproxy
daemon: true
stats: socket /var/lib/haproxy/stats

haproxy_defaults

Set parameters in defaults section of Haproxy configuration. See all parameters in Haproxy documentation

mode: http
log: global
option:
  - httplog
  - dontlognull
  - http-server-close
  - forwardfor except 127.0.0.0/8
  - redispatch
retries: 3
timeout:
  - http-request 10s
  - queue 1m
  - connect 10s
  - client 1m
  - server 1m
  - http-keep-alive 10s
  - check 10s
maxconn: 4096

haproxy_listen_stats

Set parameters in listen stats section of Haproxy configuration. See all parameters in Haproxy documentation

bind: "127.0.0.1:9000"
mode: http
maxconn: 10
timeout:
  - client 30s
  - server 30s
  - connect 30s
  - queue 30s
stats:
  - "refresh 5s"
  - "show-node"
  - 'realm Haproxy\ Statistics'
  - "auth {{ haproxy_stats_username }}:{{ haproxy_stats_password }}"
  - "uri /haproxy_stats"

haproxy_resolvers

dns:
  local:
    - dns1 127.0.0.1:53

haproxy_frontends

See all parameters in Haproxy documentation

fontend-https:
  bind: "*:443 ssl cert /etc/haproxy/ssl1.pem /etc/haproxy/ssl2.pem"
  default_backend: backend-app
frontend-http:
  bind: "*:80"
  mode: http
  option:
    - "forwardfor except 127.0.0.0/8"
    - "httplog"
    - "http-server-close"
  acl:
    - acl_test1-https hdr(host) test1.example.net
    - acl_test2-https hdr(host) test2.example.net
    - acl_blacklist src -f /etc/haproxy/blacklist.list
  use_backend:
    - backend-app if acl_test1-https
    - backend-app if acl_test2-https
    - backend-app if acl_test1-https acl_blacklist

haproxy_backends

See all parameters in Haproxy documentation

backend-app:
  mode: http
  balance: roundrobin
  stick-table: type ip size 512k expire 30m
  stick: on src
  option:
    - "ssl-hello-chk"
    - "tcp-check"
    - "log-health-checks"
    - "forwardfor header X-Forwarded-For"
  server:
    - host1 127.0.0.1:80 check maxconn 1000 inter 15s
    - host2 127.0.0.1:80 check maxconn 1000 inter 15s

haproxy_subnets_lists

Name Type Required Default Comment
key str yes name of subnets list
value list(str) yes   list of subnet
blacklist:
  - 192.168.0.0/16
  - 172.10.10.0/24
public_withlist:
  - 8.8.8.8

haproxy_userlists

restricted:
  group:
    - admin
  user:
    - admin password 84375611a53741f7e94b09eb49127f41 groups admin

haproxy_ssl_certificates

Name Type Required Default Comment
key str yes name of certificate
value str yes   the certificate
example-com: |-
  -----BEGIN CERTIFICATE-----
  MIIJQgIBADANBgkqhkiG9w0BAQEFAASCCSwwggkoAgEAAoICAQDJZs7pOmgIjXqa
  /rZx2CL4pXTo4kKv+Itj3xfrq46r4DZKQJoCHqcs/bFjtCP89xJlvbrZVmxizFOF
  mfKiNat39GNgeUaTH23+N/FOAyphayOcFk+s4X6GbdxrkHqt9IBrfK0B88bYjL/m
  ...

haproxy_http_errors

test:
  503: test-503

haproxy_http_errors_files

test-503: |-
  HTTP/1.1 503 Service Unavailable
  Cache-Control: no-cache
  Connection: close
  Content-Type: text/html

  <!DOCTYPE html>
  <html lang="en">
      <body>
          <main>
              This is my custom 503 page
          </main>
      </body>
  </html>

How to use

- hosts: server
  roles:
    - nishiki.haproxy

Development

Test with molecule and docker

  • install docker
  • install python3 and python3-pip
  • install molecule and dependencies pip3 install molecule molecule-plugins docker ansible-lint testinfra yamllint
  • run molecule test

License

Copyright (c) 2019 Adrien Waksberg

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.