diff --git a/defaults/main.yaml b/defaults/main.yaml index 334f613..27e5040 100644 --- a/defaults/main.yaml +++ b/defaults/main.yaml @@ -6,10 +6,13 @@ haproxy_cert_name: haproxy.pem haproxy_self_signed_cert: no haproxy_self_signed_cert_gen_path: "{{ haproxy_path }}/tempssl" haproxy_lua_path: "{{ haproxy_path }}/lua" +haproxy_maps_path: "{{ haproxy_path }}/maps" haproxy_stats_user: haproxy haproxy_stats_password: P@ssw0rd +haproxy_dataplaneapi: false + haproxy_default_config: global: daemon: diff --git a/tasks/Debian.yaml b/tasks/Debian.yaml index 5eff797..e390127 100644 --- a/tasks/Debian.yaml +++ b/tasks/Debian.yaml @@ -63,6 +63,7 @@ when: - 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 + - not haproxy_dataplaneapi or not haproxy_config_file_exists block: - name: Merge config for HAProxy set_fact: @@ -79,6 +80,7 @@ when: - haproxy_config_override is defined - haproxy_config_override | length > 0 + - not haproxy_dataplaneapi or not haproxy_config_file_exists block: - set_fact: haproxy_config: "{{ haproxy_config_override }}" @@ -94,6 +96,7 @@ when: - haproxy_config_base64_override is defined - haproxy_config_base64_override | length > 0 + - not haproxy_dataplaneapi or not haproxy_config_file_exists block: - set_fact: haproxy_config: "{{ haproxy_config_base64_override | b64decode }}" @@ -106,16 +109,19 @@ - Reload HAProxy - name: Add maps for HAProxy - include_tasks: map.yaml - when: haproxy_map is defined - + include_tasks: maps.yaml + when: + - haproxy_maps is defined + - name: Add lua code for HAProxy include_tasks: lua.yaml - when: haproxy_lua is defined - + when: + - haproxy_lua is defined + - name: Add certificate for HAProxy include_tasks: cert.yaml - when: haproxy_ssl + when: + - haproxy_ssl - name: Enable and start HAProxy service systemd: diff --git a/tasks/RedHat.yaml b/tasks/RedHat.yaml index 273ccb1..dc2cbeb 100644 --- a/tasks/RedHat.yaml +++ b/tasks/RedHat.yaml @@ -71,6 +71,7 @@ when: - 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 + - not haproxy_dataplaneapi or not haproxy_config_file_exists block: - name: Merge config for HAProxy set_fact: @@ -87,6 +88,7 @@ when: - haproxy_config_override is defined - haproxy_config_override | length > 0 + - not haproxy_dataplaneapi or not haproxy_config_file_exists block: - set_fact: haproxy_config: "{{ haproxy_config_override }}" @@ -102,6 +104,7 @@ when: - haproxy_config_base64_override is defined - haproxy_config_base64_override | length > 0 + - not haproxy_dataplaneapi or not haproxy_config_file_exists block: - set_fact: haproxy_config: "{{ haproxy_config_base64_override | b64decode }}" @@ -114,16 +117,19 @@ - Reload HAProxy - name: Add maps for HAProxy - include_tasks: map.yaml - when: haproxy_map is defined + include_tasks: maps.yaml + when: + - haproxy_maps is defined - name: Add lua code for HAProxy include_tasks: lua.yaml - when: haproxy_lua is defined + when: + - haproxy_lua is defined - name: Add certificate for HAProxy include_tasks: cert.yaml - when: haproxy_ssl + when: + - haproxy_ssl - name: Enable and start HAProxy service systemd: diff --git a/tasks/main.yaml b/tasks/main.yaml index 998952c..7df4f2c 100644 --- a/tasks/main.yaml +++ b/tasks/main.yaml @@ -17,5 +17,8 @@ - "vars" tags: haproxy_vars +- name: Include pre-checks.yaml + include_tasks: pre-checks.yaml + - name: Include HAProxy install include_tasks: "{{ ansible_facts['os_family'] }}.yaml" diff --git a/tasks/map.yaml b/tasks/map.yaml deleted file mode 100644 index ba28564..0000000 --- a/tasks/map.yaml +++ /dev/null @@ -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 diff --git a/tasks/maps.yaml b/tasks/maps.yaml new file mode 100644 index 0000000..42e41a0 --- /dev/null +++ b/tasks/maps.yaml @@ -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 diff --git a/tasks/pre-checks.yaml b/tasks/pre-checks.yaml new file mode 100644 index 0000000..8f5344f --- /dev/null +++ b/tasks/pre-checks.yaml @@ -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 }}"