Git Product home page Git Product logo

ansible-role-haproxy's Introduction

Install and configure haproxy on your system.

GitHub GitLab Downloads Version
github gitlab downloads Version

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

---
- name: Converge
  hosts: all
  become: true
  gather_facts: true

  roles:
    - role: robertdebock.haproxy
      haproxy_frontends:
        - name: http
          address: "*"
          port: 80
          default_backend: backend
        - name: https
          address: "*"
          port: 443
          default_backend: backend
          ssl: true
          crts:
            - /tmp/haproxy.keycrt
        - name: smtp
          address: "*"
          port: 25
          default_backend: smtp
          mode: tcp
      haproxy_backend_default_balance: roundrobin
      haproxy_backends:
        - name: backend
          httpcheck: true
          # You can tell how the health check must be done.
          # This requires haproxy version 2
          # http_check:
          #   send:
          #     method: GET
          #     uri: /health.html
          #   expect: status 200
          balance: roundrobin
          # You can refer to hosts in an Ansible group.
          # The `ansible_default_ipv4` will be used as an address to connect to.
          servers: "{{ groups['all'] }}"
          port: 8080
          options:
            - check
        - name: smtp
          balance: leastconn
          mode: tcp
          # You can also refer to a list of servers.
          servers:
            - name: first
              address: "127.0.0.1"
              port: 25
            - name: second
              address: "127.0.0.2"
              port: 25
          port: 25
        - name: vault
          mode: tcp
          httpcheck: GET /v1/sys/health HTTP/1.1
          servers: "{{ groups['all'] }}"
          http_send_name_header: Host
          port: 8200
          options:
            - check
            - check-ssl
            - ssl verify none

      haproxy_listen_default_balance: roundrobin
      haproxy_listens:
        - name: listen
          address: "*"
          httpcheck: true
          listen_port: 8081
          balance: roundrobin
          # You can refer to hosts in an Ansible group.
          # The `ansible_default_ipv4` will be used as an address to connect to.
          servers: "{{ groups['all'] }}"
          port: 8080
          options:
            - maxconn 100000

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

---
- name: Prepare
  hosts: all
  become: true
  gather_facts: false

  roles:
    - role: robertdebock.bootstrap
    - role: robertdebock.core_dependencies
    - role: robertdebock.epel
    - role: robertdebock.buildtools
    - role: robertdebock.python_pip
    - role: robertdebock.openssl
      openssl_key_directory: /tmp
      openssl_items:
        - name: haproxy
          common_name: "{{ ansible_fqdn }}"
    # This role is applied to serve as a mock "backend" server. See `molecule/default/verify.yml`.
    - role: robertdebock.httpd
      httpd_port: 8080

  vars:
    _httpd_data_directory:
      default: /var/www/html
      Alpine: /var/www/localhost/htdocs
      Suse: /srv/www/htdocs

    httpd_data_directory: "{{ _httpd_data_directory[ansible_os_family] | default(_httpd_data_directory['default'] ) }}"
  post_tasks:
    - name: Place health check
      ansible.builtin.copy:
        content: 'ok'
        dest: "{{ httpd_data_directory }}/health.html"

    - name: Place sample page
      ansible.builtin.copy:
        content: 'Hello world!'
        dest: "{{ httpd_data_directory }}/index.html"

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:

---
# defaults file for haproxy

# Configure stats in HAProxy?
haproxy_stats: true
haproxy_stats_port: 1936
haproxy_stats_bind_addr: "0.0.0.0"

# Default setttings for HAProxy.
haproxy_retries: 3
haproxy_timeout_http_request: 10s
haproxy_timeout_connect: 10s
haproxy_timeout_client: 1m
haproxy_timeout_server: 1m
haproxy_timeout_http_keep_alive: 10s
haproxy_timeout_check: 10s
haproxy_maxconn: 3000

# A list of frontends. See `molecule/
haproxy_frontends: []
haproxy_backend_default_balance: roundrobin
haproxy_backends: []

# For the listening lists:
haproxy_listen_default_balance: roundrobin
haproxy_listens: []

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

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

This role is a 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 8, 9
Debian all
Fedora all
opensuse all
Ubuntu all

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

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

If you find issues, please register them in GitHub.

Apache-2.0.

robertdebock

Please consider sponsoring me.

ansible-role-haproxy's People

Contributors

eyenx avatar heywood8 avatar mtb-xt avatar robert-de-bock avatar robertdebock avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ansible-role-haproxy's Issues

Add more flexibility in `servers` variable setup

Proposed feature

At the moment the servers are fetch from the group[all] which obliges us to have them in the inventory. And it will trigger an access to the servers (we do not want that at this stage).

Rationale

This feature is required because we will use this role for a customer deployment.

Additional context

Just ping me if anything is not clear. Thanks a lot for taking care of this!

Enable health check

Proposed feature

At the moment we cannot enable health check like described in here. We would need to be able to do this:

backend api
  option httpchk
  http-check send meth GET  uri /healthz
  http-check expect status 200
  server server1 192.168.50.2:6443 check
  server server2 192.168.50.3:6443 check
  server server3 192.168.50.4:6443 check
backend ingress-http
  option httpchk
  http-check send meth HEAD  uri /
  http-check expect status 404 # not sure about this tho
  server server1 192.168.50.2:30080 check
  server server2 192.168.50.3:30080 check
  server server3 192.168.50.4:30080 check

Rationale

To prepare SLA phase for a customer we would need this feature.

Additional context

Thanks a lot for your consideration and help!

httpcheck must be explicitly disabled

Describe the bug

Hello good sir! I'm configuring my backends in tcp mode, and I have to explicitly set
httpcheck: no
Otherwise, the template explodes with:

TASK [robertdebock.haproxy : configure software] *********************************************************************************************
task path: /home/hawara/.ansible/roles/robertdebock.haproxy/tasks/main.yml:26
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible.errors.AnsibleUndefinedVariable: 'dict object' has no attribute 'httpcheck'
fatal: [sentinel.home.hawara.nz]: FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'dict object' has no attribute 'httpcheck'"}

Playbook

- name: Configure HA control plane
  hosts: control-plane
  become: yes
  gather_facts: yes

  roles:
    - role: robertdebock.sysctl
      sysctl_items:
        - name: net.ipv4.ip_nonlocal_bind
          value: 1
    - role: robertdebock.keepalived
    - role: robertdebock.haproxy
      haproxy_frontends:
        - name: kubeAPI
          address: "172.21.34.230"
          port: 6443
          mode: tcp
          default_backend: kubeAPI_backend
        - name: konnectivity
          address: "172.21.34.230"
          port: 8132
          mode: tcp
          default_backend: konnectivity_backend
        - name: controllerJoinAPI
          address: "172.21.34.230"
          port: 9443
          mode: tcp
          default_backend: controllerJoinAPI_backend
      haproxy_backend_default_balance: roundrobin
      haproxy_backends:
        - name: kubeAPI_backend
          httpcheck: no
          balance: roundrobin
          servers: "{{ groups['control-plane'] }}"
          port: 6443
          options:
            - check
            - check-ssl
            - verify none
        - name: konnectivity_backend
          httpcheck: no
          balance: roundrobin
          servers: "{{ groups['control-plane'] }}"
          port: 8132
          options:
            - check
            - check-ssl
            - verify none
        - name: controllerJoinAPI_backend
          httpcheck: no
          balance: roundrobin
          servers: "{{ groups['control-plane'] }}"
          port: 9443
          options:
            - check
            - check-ssl
            - verify none

Output

Show at least the error, possible related output, maybe just all the output.
image

Environment

  • Control node OS: [e.g. Debian 9] (cat /etc/os-release)
    Arch Linux
  • Control node Ansible version: [e.g. 2.9.1] (ansible --version)
    ansible [core 2.13.3]
  • Managed node OS: [e.g. CentOS 7] (cat /etc/os-release)
    Ubuntu 22.04.1 LTS

Please consider sponsoring me. ◀️ ✔️

Add configurable `mode` for backends/frontends

Proposed feature

At the moment there is no way to configure the mode of the frontends/backens (http, tcp...). It would be nice to have this feature available!

Rationale

This feature is required because we will use this role for a customer deployment.

Additional context

Just ping me if anything is not clear. Thanks a lot for taking care of this!

Default on CentOS 7 this installs 1.5

I think default on CentOS 7 this installs version 1.5 which is no longer supported. Which has reached EOF. https://www.haproxy.org/

There is a epel version haproxy18 which has 1.8 which looks better but I don't know what that is. For example it doesn't include a service, there is no config directory.

I don't have any experience with HAProxy. Should we use a paid version? Or Install this from source? Some people are installing from source it seems for example https://laptrinhx.com/how-to-install-haproxy-1-9-on-centos-7-1410983782/

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.