Don't override haproxy.cfg if it is manageabled by haproxy data plane api

This commit is contained in:
ace 2024-09-29 21:34:44 +03:00
parent 42ecb387b6
commit daa1b0d01f
Signed by: ace
GPG Key ID: 2C08973DD37A76FD
7 changed files with 49 additions and 18 deletions

View File

@ -6,10 +6,13 @@ haproxy_cert_name: haproxy.pem
haproxy_self_signed_cert: no haproxy_self_signed_cert: no
haproxy_self_signed_cert_gen_path: "{{ haproxy_path }}/tempssl" haproxy_self_signed_cert_gen_path: "{{ haproxy_path }}/tempssl"
haproxy_lua_path: "{{ haproxy_path }}/lua" haproxy_lua_path: "{{ haproxy_path }}/lua"
haproxy_maps_path: "{{ haproxy_path }}/maps"
haproxy_stats_user: haproxy haproxy_stats_user: haproxy
haproxy_stats_password: P@ssw0rd haproxy_stats_password: P@ssw0rd
haproxy_dataplaneapi: false
haproxy_default_config: haproxy_default_config:
global: global:
daemon: daemon:

View File

@ -63,6 +63,7 @@
when: when:
- haproxy_config_override is not defined or haproxy_config_override | length <= 0 - haproxy_config_override is not defined or haproxy_config_override | length <= 0
- haproxy_config_base64_override is not defined or haproxy_config_base64_override | length <= 0 - haproxy_config_base64_override is not defined or haproxy_config_base64_override | length <= 0
- not haproxy_dataplaneapi or not haproxy_config_file_exists
block: block:
- name: Merge config for HAProxy - name: Merge config for HAProxy
set_fact: set_fact:
@ -79,6 +80,7 @@
when: when:
- haproxy_config_override is defined - haproxy_config_override is defined
- haproxy_config_override | length > 0 - haproxy_config_override | length > 0
- not haproxy_dataplaneapi or not haproxy_config_file_exists
block: block:
- set_fact: - set_fact:
haproxy_config: "{{ haproxy_config_override }}" haproxy_config: "{{ haproxy_config_override }}"
@ -94,6 +96,7 @@
when: when:
- haproxy_config_base64_override is defined - haproxy_config_base64_override is defined
- haproxy_config_base64_override | length > 0 - haproxy_config_base64_override | length > 0
- not haproxy_dataplaneapi or not haproxy_config_file_exists
block: block:
- set_fact: - set_fact:
haproxy_config: "{{ haproxy_config_base64_override | b64decode }}" haproxy_config: "{{ haproxy_config_base64_override | b64decode }}"
@ -106,16 +109,19 @@
- Reload HAProxy - Reload HAProxy
- name: Add maps for HAProxy - name: Add maps for HAProxy
include_tasks: map.yaml include_tasks: maps.yaml
when: haproxy_map is defined when:
- haproxy_maps is defined
- name: Add lua code for HAProxy - name: Add lua code for HAProxy
include_tasks: lua.yaml include_tasks: lua.yaml
when: haproxy_lua is defined when:
- haproxy_lua is defined
- name: Add certificate for HAProxy - name: Add certificate for HAProxy
include_tasks: cert.yaml include_tasks: cert.yaml
when: haproxy_ssl when:
- haproxy_ssl
- name: Enable and start HAProxy service - name: Enable and start HAProxy service
systemd: systemd:

View File

@ -71,6 +71,7 @@
when: when:
- haproxy_config_override is not defined or haproxy_config_override | length <= 0 - haproxy_config_override is not defined or haproxy_config_override | length <= 0
- haproxy_config_base64_override is not defined or haproxy_config_base64_override | length <= 0 - haproxy_config_base64_override is not defined or haproxy_config_base64_override | length <= 0
- not haproxy_dataplaneapi or not haproxy_config_file_exists
block: block:
- name: Merge config for HAProxy - name: Merge config for HAProxy
set_fact: set_fact:
@ -87,6 +88,7 @@
when: when:
- haproxy_config_override is defined - haproxy_config_override is defined
- haproxy_config_override | length > 0 - haproxy_config_override | length > 0
- not haproxy_dataplaneapi or not haproxy_config_file_exists
block: block:
- set_fact: - set_fact:
haproxy_config: "{{ haproxy_config_override }}" haproxy_config: "{{ haproxy_config_override }}"
@ -102,6 +104,7 @@
when: when:
- haproxy_config_base64_override is defined - haproxy_config_base64_override is defined
- haproxy_config_base64_override | length > 0 - haproxy_config_base64_override | length > 0
- not haproxy_dataplaneapi or not haproxy_config_file_exists
block: block:
- set_fact: - set_fact:
haproxy_config: "{{ haproxy_config_base64_override | b64decode }}" haproxy_config: "{{ haproxy_config_base64_override | b64decode }}"
@ -114,16 +117,19 @@
- Reload HAProxy - Reload HAProxy
- name: Add maps for HAProxy - name: Add maps for HAProxy
include_tasks: map.yaml include_tasks: maps.yaml
when: haproxy_map is defined when:
- haproxy_maps is defined
- name: Add lua code for HAProxy - name: Add lua code for HAProxy
include_tasks: lua.yaml include_tasks: lua.yaml
when: haproxy_lua is defined when:
- haproxy_lua is defined
- name: Add certificate for HAProxy - name: Add certificate for HAProxy
include_tasks: cert.yaml include_tasks: cert.yaml
when: haproxy_ssl when:
- haproxy_ssl
- name: Enable and start HAProxy service - name: Enable and start HAProxy service
systemd: systemd:

View File

@ -17,5 +17,8 @@
- "vars" - "vars"
tags: haproxy_vars tags: haproxy_vars
- name: Include pre-checks.yaml
include_tasks: pre-checks.yaml
- name: Include HAProxy install - name: Include HAProxy install
include_tasks: "{{ ansible_facts['os_family'] }}.yaml" include_tasks: "{{ ansible_facts['os_family'] }}.yaml"

View File

@ -1,8 +0,0 @@
---
- name: Write maps for HAProxy
copy:
dest: "{{ haproxy_path }}/{{ item.key }}"
content: "{{ item.value }}"
loop: "{{ haproxy_map | dict2items }}"
notify:
- Reload HAProxy

13
tasks/maps.yaml Normal file
View File

@ -0,0 +1,13 @@
---
- name: Create maps dir for HAProxy
file:
path: "{{ haproxy_maps_path }}"
state: directory
- name: Write maps for HAProxy
copy:
dest: "{{ haproxy_maps_path }}/{{ item.key }}"
content: "{{ item.value }}"
loop: "{{ haproxy_map | dict2items }}"
notify:
- Reload HAProxy

8
tasks/pre-checks.yaml Normal file
View File

@ -0,0 +1,8 @@
- name: Check if haproxy.cfg exists
stat:
path: "/etc/haproxy/haproxy.cfg"
register: haproxy_config_file_exists_result
- name: Set fact about existing haproxy.cfg
set_fact:
haproxy_config_file_exists: "{{ true if haproxy_config_file_exists_result.stat.exists else false }}"