Skip to content

buluma/ansible-role-haproxy

Install and configure haproxy on your system.

GitHub Issues Pull Requests Version Downloads
github Issues PullRequests Version Ansible Role

This example is taken from molecule/default/converge.yml and is tested on each push, pull request and release.

---
- become: true
  gather_facts: true
  hosts: all
  name: Converge
  roles:
    - haproxy_backend_default_balance: roundrobin
      haproxy_backends:
        - balance: roundrobin
          httpcheck: true
          name: backend
          options:
            - check
          port: 8080
          servers: "{{ groups['all'] }}"
        - balance: leastconn
          mode: tcp
          name: smtp
          port: 25
          servers:
            - address: 127.0.0.1
              name: first
              port: 25
            - address: 127.0.0.2
              name: second
              port: 25
        - http_send_name_header: Host
          httpcheck: GET /v1/sys/health HTTP/1.1
          mode: tcp
          name: vault
          options:
            - check
            - check-ssl
            - ssl verify none
          port: 8200
          servers: "{{ groups['all'] }}"
      haproxy_frontends:
        - address: "*"
          default_backend: backend
          name: http
          port: 80
        - address: "*"
          crts:
            - /tmp/haproxy.keycrt
          default_backend: backend
          name: https
          port: 443
          ssl: true
        - address: "*"
          default_backend: smtp
          mode: tcp
          name: smtp
          port: 25
      haproxy_listen_default_balance: roundrobin
      haproxy_listens:
        - address: "*"
          balance: roundrobin
          httpcheck: true
          listen_port: 8081
          name: listen
          options:
            - maxconn 100000
          port: 8080
          servers: "{{ groups['all'] }}"
      role: buluma.haproxy

The machine needs to be prepared. In CI this is done using molecule/default/prepare.yml:

---
- become: true
  gather_facts: false
  hosts: all
  name: Prepare
  post_tasks:
    - ansible.builtin.copy:
        content: ok
        dest: "{{ httpd_data_directory }}/health.html"
        group: root
        mode: "0644"
        owner: root
      name: Place health check
    - ansible.builtin.copy:
        content: Hello world!
        dest: "{{ httpd_data_directory }}/index.html"
        group: root
        mode: "0644"
        owner: root
      name: Place sample page
  roles:
    - role: buluma.bootstrap
    - role: buluma.core_dependencies
    - role: buluma.epel
    - role: buluma.buildtools
    - role: buluma.python_pip
    - openssl_items:
        - common_name: "{{ ansible_fqdn }}"
          name: haproxy
      openssl_key_directory: /tmp
      role: buluma.openssl
    - httpd_port: 8080
      role: buluma.httpd
  vars:
    _httpd_data_directory:
      Alpine: /var/www/localhost/htdocs
      Suse: /srv/www/htdocs
      default: /var/www/html
    ansible_python_interpreter: /usr/bin/python3
    httpd_data_directory:
      "{{ _httpd_data_directory[ansible_os_family] | default(_httpd_data_directory['default']
      ) }}"

Also see a full explanation and example on how to use these roles.

The default values for the variables are set in defaults/main.yml:

---
haproxy_backend_default_balance: roundrobin
haproxy_backends: []
haproxy_frontends: []
haproxy_listen_default_balance: roundrobin
haproxy_listens: []
haproxy_maxconn: 3000
haproxy_retries: 3
haproxy_stats: true
haproxy_stats_bind_addr: "0.0.0.0"
haproxy_stats_port: 1936
haproxy_timeout_check: 10s
haproxy_timeout_client: 1m
haproxy_timeout_connect: 10s
haproxy_timeout_http_keep_alive: 10s
haproxy_timeout_http_request: 10s
haproxy_timeout_server: 1m

The following roles are used to prepare a system. You can prepare your system in another way.

Requirement GitHub
buluma.bootstrap Build Status GitHub
buluma.buildtools Build Status GitHub
buluma.core_dependencies Build Status GitHub
buluma.epel Build Status GitHub
buluma.httpd Build Status GitHub
buluma.openssl Build Status GitHub
buluma.python_pip Build Status GitHub

This role is part of many compatible roles. Have a look at the documentation of these roles for further information.

Here is an overview of related roles:

dependencies

This role has been tested on these container images:

container tags
EL all
Debian all
Fedora all
Ubuntu all

The minimum version of Ansible required is 2.12, tests have been done on:

  • The previous version.
  • The current version.
  • The development version.

If you find issues, please register them on GitHub.

Apache-2.0.

buluma

About

Install and configure haproxy on your system.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages