Skip to content

Commit

Permalink
Lots of updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
buluma committed Nov 18, 2023
1 parent 0d22403 commit 59b3811
Show file tree
Hide file tree
Showing 12 changed files with 327 additions and 39 deletions.
1 change: 0 additions & 1 deletion .ansible-lint
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Ansible managed
#
exclude_paths:
- meta/preferences.yml
- molecule/default/prepare.yml
- molecule/default/converge.yml
- molecule/default/verify.yml
Expand Down
10 changes: 10 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Configure stats in HAProxy?
haproxy_stats: yes
haproxy_stats_port: 1936
haproxy_stats_bind_addr: "0.0.0.0"

# Default setttings for HAProxy.
haproxy_retries: 3
Expand All @@ -14,3 +15,12 @@ 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: []
2 changes: 0 additions & 2 deletions handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,3 @@
ansible.builtin.service:
name: haproxy
state: restarted
when:
- not ansible_check_mode | bool
73 changes: 73 additions & 0 deletions meta/argument_specs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
---

argument_specs:
main:
short_description: "Install and configure haproxy on your system."
description: >
Install and configure haproxy on your system.
author: Shadow Walker
options:
haproxy_stats:
type: "bool"
default: yes
description: "Configure stats in HAProxy?"
haproxy_stats_port:
type: "int"
default: 1936
description: "The port for HAProxy stats."
haproxy_stats_bind_addr:
type: "str"
default: "0.0.0.0"
description: "The address to bind HAProxy stats to."
haproxy_retries:
type: "int"
default: 3
description: "The number of retries."
haproxy_timeout_http_request:
type: "str"
default: "10s"
description: "The timeout for HTTP requests."
haproxy_timeout_connect:
type: "str"
default: "10s"
description: "The timeout for connecting."
haproxy_timeout_client:
type: "str"
default: "1m"
description: "The timeout for clients."
haproxy_timeout_server:
type: "str"
default: "1m"
description: "The timeout for servers."
haproxy_timeout_http_keep_alive:
type: "str"
default: "10s"
description: "The interval for HTTP keep-alive."
haproxy_timeout_check:
type: "str"
default: "10s"
description: "The timeout for checks."
haproxy_maxconn:
type: "int"
default: 3000
description: "The maximum number of connections."
haproxy_frontends:
type: "list"
default: []
description: "A list of frontends."
haproxy_backend_default_balance:
type: "str"
default: "roundrobin"
description: "The default balance for backends."
haproxy_backends:
type: "list"
default: []
description: "A list of backends."
haproxy_listen_default_balance:
type: "str"
default: "roundrobin"
description: "The default balance for listens."
haproxy_listens:
type: "list"
default: []
description: "A list of listens."
6 changes: 0 additions & 6 deletions meta/exception.yml

This file was deleted.

2 changes: 2 additions & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ galaxy_info:
- name: EL
versions:
- "8"
- "9"
- name: Debian
versions:
- all
Expand All @@ -27,5 +28,6 @@ galaxy_info:
galaxy_tags:
- cloud
- haproxy
- networking

dependencies: []
33 changes: 31 additions & 2 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@
haproxy_backends:
- name: backend
httpcheck: yes
# 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.
Expand All @@ -35,8 +42,8 @@
options:
- check
- name: smtp
httpcheck: yes
balance: roundrobin
balance: leastconn
mode: tcp
# You can also refer to a list of servers.
servers:
- name: first
Expand All @@ -46,5 +53,27 @@
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: yes
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
18 changes: 18 additions & 0 deletions molecule/default/prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,21 @@
# This role is applied to serve as a mock "backend" server. See `molecule/default/verify.yml`.
- role: buluma.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"
8 changes: 4 additions & 4 deletions molecule/default/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
ansible.builtin.package:
name: socat
state: present
notify:
- Uninstall testing requirements

- name: Check if ports responds
- name: Check if port responds
ansible.builtin.wait_for:
port: "{{ item }}"
loop:
Expand All @@ -23,18 +25,16 @@
validate_certs: no
status_code:
- 200
- 403
loop:
- "http://localhost/"
- "https://localhost/"

- name: Check if stats are available
ansible.builtin.shell:
cmd: echo "show stat" | socat unix-connect:/var/lib/haproxy/stats stdio
cmd: "echo 'show stat' | socat unix-connect:/var/lib/haproxy/stats stdio"
changed_when: no

handlers:

- name: Uninstall testing requirements
ansible.builtin.package:
name: socat
Expand Down
Loading

0 comments on commit 59b3811

Please sign in to comment.