feat: initial commit

This commit is contained in:
Simon Cornet 2026-04-17 13:34:09 +02:00
commit 214e91a391
16 changed files with 546 additions and 93 deletions

23
.ansible-lint Normal file
View file

@ -0,0 +1,23 @@
---
exclude_paths:
- ".gitlab/*"
- ".gitlab-ci.yml"
- "defaults/main.yaml"
- "meta/main.yaml"
- "vars/*"
kinds:
- playbook: "**/*.{yml,yaml}"
skip_list:
- "command-shell"
- "experimental"
- "git-latest"
- "no-changed-when"
- "no-handler"
- "name[casing]"
- "name[template]"
- "risky-file-permissions"
- "schema[playbook]"
- "var-naming[no-role-prefix]"

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
.ansible

13
.gitlab-ci.yml Normal file
View file

@ -0,0 +1,13 @@
---
# gitlab stages
stages:
- "gitleaks"
- "linting"
# include components
include:
- component: "$CI_SERVER_FQDN/components/ansible/linting@v3.0.3"
- component: "$CI_SERVER_FQDN/components/gitleaks/gitleaks@v1.0.0"
- component: "$CI_SERVER_FQDN/components/markdownlint/markdownlint@1.0.0"
- component: "$CI_SERVER_FQDN/components/yamllint/yamllint@1.0.2"

12
.markdownlint-cli2.jsonc Normal file
View file

@ -0,0 +1,12 @@
{
// files to lint
"globs": [
"readme.md"
],
// linting rules
"config": {
"MD013": {
"line_length": 120
}
}
}

30
.yamllint Normal file
View file

@ -0,0 +1,30 @@
---
extends: 'default'
rules:
braces:
max-spaces-inside: 1
forbid: true
comments:
min-spaces-from-content: 1
comments-indentation: false
empty-lines:
max: 2
indentation:
spaces: 2
check-multi-line-strings: true
line-length:
max: 120
allow-non-breakable-words: true
allow-non-breakable-inline-mappings: true
new-line-at-end-of-file: 'enable'
octal-values:
forbid-implicit-octal: true
forbid-explicit-octal: true
truthy:
allowed-values:
- 'true'
- 'false'
quoted-strings:
quote-type: 'any'
required: true

View file

@ -1,93 +0,0 @@
# role-haproxy
## Getting started
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
## Add your files
* [Create](https://docs.gitlab.com/user/project/repository/web_editor/#create-a-file) or [upload](https://docs.gitlab.com/user/project/repository/web_editor/#upload-a-file) files
* [Add files using the command line](https://docs.gitlab.com/topics/git/add_files/#add-files-to-a-git-repository) or push an existing Git repository with the following command:
```
cd existing_repo
git remote add origin https://gitlab.simoncor.net/ansible/role-haproxy.git
git branch -M main
git push -uf origin main
```
## Integrate with your tools
* [Set up project integrations](https://gitlab.simoncor.net/ansible/role-haproxy/-/settings/integrations)
## Collaborate with your team
* [Invite team members and collaborators](https://docs.gitlab.com/user/project/members/)
* [Create a new merge request](https://docs.gitlab.com/user/project/merge_requests/creating_merge_requests/)
* [Automatically close issues from merge requests](https://docs.gitlab.com/user/project/issues/managing_issues/#closing-issues-automatically)
* [Enable merge request approvals](https://docs.gitlab.com/user/project/merge_requests/approvals/)
* [Set auto-merge](https://docs.gitlab.com/user/project/merge_requests/auto_merge/)
## Test and Deploy
Use the built-in continuous integration in GitLab.
* [Get started with GitLab CI/CD](https://docs.gitlab.com/ci/quick_start/)
* [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/user/application_security/sast/)
* [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/topics/autodevops/requirements/)
* [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/user/clusters/agent/)
* [Set up protected environments](https://docs.gitlab.com/ci/environments/protected_environments/)
***
# Editing this README
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
## Name
Choose a self-explaining name for your project.
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
## Contributing
State if you are open to contributions and what your requirements are for accepting them.
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
## License
For open source projects, say how it is licensed.
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.

38
defaults/main.yaml Normal file
View file

@ -0,0 +1,38 @@
---
# global settings
haproxy_global:
log: "/dev/log local2"
chroot: "/var/lib/haproxy"
pidfile: "/var/run/haproxy.pid"
maxconn: 35000
user: "haproxy"
group: "haproxy"
daemon: true
stats_socket: "/var/lib/haproxy/stats user haproxy group haproxy mode 660 level admin"
# default settings
haproxy_defaults:
log: "global"
mode: "tcp"
option: "tcplog"
timeout_check: "5s"
timeout_connect: "10s"
timeout_client: "600s"
timeout_server: "600s"
# stats listener (optional)
haproxy_stats:
enabled: false
bind: "0.0.0.0:9000"
mode: "http"
uri: "/"
show_node: true
refresh: "10s"
auth: "admin:password"
# frontends
haproxy_frontends: []
# backends
haproxy_backends: []

View file

@ -0,0 +1,91 @@
---
# Example playbook using role-haproxy
# This recreates the configuration from the README example
- name: "Deploy HAProxy Load Balancer"
hosts: "haproxy_servers"
become: true
vars:
# enable stats interface
haproxy_stats:
enabled: true
bind: "10.120.32.10:9000"
mode: "http"
uri: "/"
show_node: true
refresh: "10s"
auth: "admitcreation:gZ4hWWeMWy7Bd8"
# frontends
haproxy_frontends:
# http frontend
- name: "http-in"
bind: "10.120.32.15:80"
default_backend: "waf_itcreation_tools_http"
# https frontend
- name: "https-in"
bind: "10.120.32.15:443"
default_backend: "waf_itcreation_tools_https"
# backends
haproxy_backends:
# http backend with simple load balancing
- name: "waf_itcreation_tools_http"
balance: "source"
hash_type: "consistent"
options:
- "option httpchk GET /health"
servers:
# waf0.itcreation.tools
- name: "waf0.itcreation.tools"
address: "10.120.32.20:80"
check: true
send_proxy: true
# waf1.itcreation.tools
- name: "waf1.itcreation.tools"
address: "10.120.32.21:80"
check: true
send_proxy: true
# https backend with SSL session persistence
- name: "waf_itcreation_tools_https"
balance: "roundrobin"
stick_table: "type binary len 2048 size 300k expire 30m"
acls:
- "clienthello req.ssl_hello_type 1"
- "serverhello res.ssl_hello_type 2"
tcp_request:
- "inspect-delay 10s"
- "content accept if clienthello"
tcp_response:
- "content accept if serverhello"
stick:
- "on req.payload_lv(43,1) if clienthello"
- "store-response res.payload_lv(43,1) if serverhello"
options:
- "option httpchk GET /health"
servers:
# waf0.itcreation.tools
- name: "waf0.itcreation.tools"
address: "10.120.32.20:443"
send_proxy: true
check: true
extra_params: "check-ssl verify none"
# waf0.itcreation.tools
- name: "waf1.itcreation.tools"
address: "10.120.32.21:443"
send_proxy: true
check: true
extra_params: "check-ssl verify none"
roles:
- "role-haproxy"

8
handlers/main.yaml Normal file
View file

@ -0,0 +1,8 @@
---
# restart haproxy
- name: "restart haproxy"
ansible.builtin.systemd:
name: "haproxy"
state: "restarted"
enabled: true

8
meta/main.yaml Normal file
View file

@ -0,0 +1,8 @@
---
galaxy_info:
author: "siempie"
description: "install and configure HAProxy load balancer"
license: "MIT"
role_name: "haproxy"
dependencies: []

169
readme.md Normal file
View file

@ -0,0 +1,169 @@
# Ansible Role: HAProxy
Install and configure HAProxy load balancer with flexible frontends, backends, and stats.
## Variables
### Global Settings
| Variable | Required | Default | Description |
|----------|----------|---------|-------------|
| `haproxy_global.log` | No | `/dev/log local2` | Log target |
| `haproxy_global.chroot` | No | `/var/lib/haproxy` | Chroot directory |
| `haproxy_global.pidfile` | No | `/var/run/haproxy.pid` | PID file location |
| `haproxy_global.maxconn` | No | `35000` | Maximum connections |
| `haproxy_global.user` | No | `haproxy` | User to run as |
| `haproxy_global.group` | No | `haproxy` | Group to run as |
| `haproxy_global.daemon` | No | `true` | Run as daemon |
| `haproxy_global.stats_socket` | No | See defaults | Stats socket configuration |
### Default Settings
| Variable | Required | Default | Description |
|----------|----------|---------|-------------|
| `haproxy_defaults.log` | No | `global` | Log setting |
| `haproxy_defaults.mode` | No | `tcp` | Default mode (tcp/http) |
| `haproxy_defaults.option` | No | `tcplog` | Default option |
| `haproxy_defaults.timeout_check` | No | `5s` | Health check timeout |
| `haproxy_defaults.timeout_connect` | No | `10s` | Connection timeout |
| `haproxy_defaults.timeout_client` | No | `600s` | Client timeout |
| `haproxy_defaults.timeout_server` | No | `600s` | Server timeout |
### Stats Listener
| Variable | Required | Default | Description |
|----------|----------|---------|-------------|
| `haproxy_stats.enabled` | No | `false` | Enable stats interface |
| `haproxy_stats.bind` | No | `10.120.32.10:9000` | Bind address for stats |
| `haproxy_stats.mode` | No | `http` | Stats mode |
| `haproxy_stats.uri` | No | `/` | Stats URI path |
| `haproxy_stats.show_node` | No | `true` | Show node name |
| `haproxy_stats.refresh` | No | `10s` | Refresh interval |
| `haproxy_stats.auth` | No | `admin:password` | Basic auth credentials |
### Frontends
| Variable | Required | Default | Description |
|----------|----------|---------|-------------|
| `haproxy_frontends` | No | `[]` | List of frontends |
| `haproxy_frontends[].name` | Yes | - | Frontend name |
| `haproxy_frontends[].bind` | Yes | - | Bind address and port |
| `haproxy_frontends[].default_backend` | Yes | - | Default backend name |
| `haproxy_frontends[].mode` | No | - | Override default mode |
| `haproxy_frontends[].options` | No | `[]` | Additional options |
### Backends
| Variable | Required | Default | Description |
|----------|----------|---------|-------------|
| `haproxy_backends` | No | `[]` | List of backends |
| `haproxy_backends[].name` | Yes | - | Backend name |
| `haproxy_backends[].balance` | No | - | Load balancing algorithm |
| `haproxy_backends[].hash_type` | No | - | Hash type for balancing |
| `haproxy_backends[].mode` | No | - | Override default mode |
| `haproxy_backends[].stick_table` | No | - | Stick table configuration |
| `haproxy_backends[].acls` | No | `[]` | List of ACL rules |
| `haproxy_backends[].tcp_request` | No | `[]` | TCP request rules |
| `haproxy_backends[].tcp_response` | No | `[]` | TCP response rules |
| `haproxy_backends[].stick` | No | `[]` | Stick rules |
| `haproxy_backends[].options` | No | `[]` | Additional options |
| `haproxy_backends[].servers` | Yes | - | List of backend servers |
| `haproxy_backends[].servers[].name` | Yes | - | Server name |
| `haproxy_backends[].servers[].address` | Yes | - | Server address:port |
| `haproxy_backends[].servers[].check` | No | `false` | Enable health checks |
| `haproxy_backends[].servers[].send_proxy` | No | `false` | Enable send-proxy |
| `haproxy_backends[].servers[].extra_params` | No | - | Additional server parameters |
## Full Example
```yaml
---
# Example playbook using role-haproxy
- name: "Deploy HAProxy Load Balancer"
hosts: "haproxy_servers"
become: true
vars:
# enable stats interface
haproxy_stats:
enabled: true
bind: "10.120.32.10:9000"
mode: "http"
uri: "/"
show_node: true
refresh: "10s"
auth: "admitcreation:gZ4hWWeMWy7Bd8"
# frontends
haproxy_frontends:
# http frontend
- name: "http-in"
bind: "10.120.32.15:80"
default_backend: "waf_itcreation_tools_http"
# https frontend
- name: "https-in"
bind: "10.120.32.15:443"
default_backend: "waf_itcreation_tools_https"
# backends
haproxy_backends:
# http backend with simple load balancing
- name: "waf_itcreation_tools_http"
balance: "source"
hash_type: "consistent"
options:
- "option httpchk GET /health"
servers:
# waf0.itcreation.tools
- name: "waf0.itcreation.tools"
address: "10.120.32.20:80"
check: true
send_proxy: true
# waf1.itcreation.tools
- name: "waf1.itcreation.tools"
address: "10.120.32.21:80"
check: true
send_proxy: true
# https backend with SSL session persistence
- name: "waf_itcreation_tools_https"
balance: "roundrobin"
stick_table: "type binary len 2048 size 300k expire 30m"
acls:
- "clienthello req.ssl_hello_type 1"
- "serverhello res.ssl_hello_type 2"
tcp_request:
- "inspect-delay 10s"
- "content accept if clienthello"
tcp_response:
- "content accept if serverhello"
stick:
- "on req.payload_lv(43,1) if clienthello"
- "store-response res.payload_lv(43,1) if serverhello"
options:
- "option httpchk GET /health"
servers:
# waf0.itcreation.tools
- name: "waf0.itcreation.tools"
address: "10.120.32.20:443"
send_proxy: true
check: true
extra_params: "check-ssl verify none"
# waf0.itcreation.tools
- name: "waf1.itcreation.tools"
address: "10.120.32.21:443"
send_proxy: true
check: true
extra_params: "check-ssl verify none"
roles:
- "role-haproxy"
```

4
renovate.json Normal file
View file

@ -0,0 +1,4 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [ "local>cicd/renovate:ansible" ]
}

12
tasks/config.yaml Normal file
View file

@ -0,0 +1,12 @@
---
# configure haproxy.cfg
- name: "config - haproxy.cfg"
ansible.builtin.template:
src: "templates/haproxy.cfg.j2"
dest: "/etc/haproxy/haproxy.cfg"
owner: "root"
group: "root"
mode: "0644"
validate: "haproxy -c -f %s"
notify: "restart haproxy"

16
tasks/install.yaml Normal file
View file

@ -0,0 +1,16 @@
---
# install haproxy
- name: "install - haproxy"
ansible.builtin.apt:
name: "haproxy"
state: "latest"
cache_valid_time: "120"
when: 'ansible_os_family == "Debian"'
# start haproxy service
- name: "service - start haproxy"
ansible.builtin.systemd:
name: "haproxy"
state: "started"
enabled: true

9
tasks/main.yaml Normal file
View file

@ -0,0 +1,9 @@
---
# install haproxy
- name: "install"
ansible.builtin.import_tasks: "install.yaml"
# configure haproxy
- name: "config"
ansible.builtin.import_tasks: "config.yaml"

112
templates/haproxy.cfg.j2 Normal file
View file

@ -0,0 +1,112 @@
# global
global
log {{ haproxy_global.log }}
chroot {{ haproxy_global.chroot }}
pidfile {{ haproxy_global.pidfile }}
maxconn {{ haproxy_global.maxconn }}
group {{ haproxy_global.group }}
user {{ haproxy_global.user }}
{%- if haproxy_global.daemon %}
daemon
{%- endif %}
stats socket {{ haproxy_global.stats_socket }}
# default settings
defaults
log {{ haproxy_defaults.log }}
mode {{ haproxy_defaults.mode }}
option {{ haproxy_defaults.option }}
timeout check {{ haproxy_defaults.timeout_check }}
timeout connect {{ haproxy_defaults.timeout_connect }}
timeout client {{ haproxy_defaults.timeout_client }}
timeout server {{ haproxy_defaults.timeout_server }}
{%- if haproxy_stats.enabled %}
# stats
listen stats
bind {{ haproxy_stats.bind }}
mode {{ haproxy_stats.mode }}
stats enable
stats uri {{ haproxy_stats.uri }}
{%- if haproxy_stats.show_node %}
stats show-node
{%- endif %}
stats refresh {{ haproxy_stats.refresh }}
stats auth {{ haproxy_stats.auth }}
{%- endif %}
{%- for frontend in haproxy_frontends %}
# frontend - {{ frontend.name }}
frontend {{ frontend.name }}
bind {{ frontend.bind }}
{%- if frontend.mode is defined %}
mode {{ frontend.mode }}
{%- endif %}
{%- if frontend.options is defined %}
{%- for option in frontend.options %}
{{ option }}
{%- endfor %}
{%- endif %}
default_backend {{ frontend.default_backend }}
{%- endfor %}
{%- for backend in haproxy_backends %}
# backend {{ backend.name }}
backend {{ backend.name }}
{%- if backend.balance is defined %}
balance {{ backend.balance }}
{%- endif %}
{%- if backend.hash_type is defined %}
hash-type {{ backend.hash_type }}
{%- endif %}
{%- if backend.mode is defined %}
mode {{ backend.mode }}
{%- endif %}
{%- if backend.stick_table is defined %}
stick-table {{ backend.stick_table }}
{%- endif %}
{%- if backend.acls is defined %}
{%- for acl in backend.acls %}
acl {{ acl }}
{%- endfor %}
{%- endif %}
{%- if backend.tcp_request is defined %}
{%- for tcp_req in backend.tcp_request %}
tcp-request {{ tcp_req }}
{%- endfor %}
{%- endif %}
{%- if backend.tcp_response is defined %}
{%- for tcp_resp in backend.tcp_response %}
tcp-response {{ tcp_resp }}
{%- endfor %}
{%- endif %}
{%- if backend.stick is defined %}
{%- for stick in backend.stick %}
stick {{ stick }}
{%- endfor %}
{%- endif %}
{%- if backend.options is defined %}
{%- for option in backend.options %}
{{ option }}
{%- endfor %}
{%- endif %}
{%- for server in backend.servers %}
server {{ server.name }} {{ server.address }}{% if server.send_proxy | default(false) %} send-proxy{% endif %}{% if server.check | default(false) %} check{% endif %}{% if server.extra_params is defined %} {{ server.extra_params }}{% endif %}
{%- endfor %}
{%- endfor %}