diff --git a/defaults/main.yaml b/defaults/main.yaml index 21fda4a..334f613 100644 --- a/defaults/main.yaml +++ b/defaults/main.yaml @@ -1,3 +1,4 @@ +haproxy_version: "" haproxy_path: /etc/haproxy haproxy_ssl: no haproxy_ssl_path: "{{ haproxy_path }}/ssl" diff --git a/handlers/main.yaml b/handlers/main.yaml index 411a86a..c691fb9 100644 --- a/handlers/main.yaml +++ b/handlers/main.yaml @@ -4,11 +4,13 @@ name: "{{ haproxy_unit_name }}" state: reloaded daemon_reload: yes - when: haproxy_enable_and_start.changed + masked: no + when: not haproxy_enable_and_start.changed - name: Restart HAProxy systemd: name: "{{ haproxy_unit_name }}" - state: reloaded + state: restarted daemon_reload: yes - when: haproxy_enable_and_start.changed + masked: no + when: not haproxy_enable_and_start.changed diff --git a/tasks/Debian.yaml b/tasks/Debian.yaml index 9fa9f92..dca449e 100644 --- a/tasks/Debian.yaml +++ b/tasks/Debian.yaml @@ -18,28 +18,27 @@ ansible.builtin.systemd: name: "{{ haproxy_unit_name }}" masked: yes - when: haproxy_package_name not in ansible_facts.packages or ansible_facts.packages[haproxy_package_name][0]['version'] != (haproxy_version|string + "-" + haproxy_version_build|string) + changed_when: false -- name: "Install {{ haproxy_package_name }}-{{ haproxy_version }}-{{ haproxy_version_build }}" +- name: "Install {{ haproxy_package }}" apt: name: "{{ haproxy_package }}" + state: "{{ 'latest' if haproxy_version == 'latest' else 'present' }}" update_cache: yes register: haproxy_setup - when: haproxy_package_name not in ansible_facts.packages + notify: + - Restart HAProxy -- name: "Update {{ haproxy_package_name }}-{{ haproxy_version }}-{{ haproxy_version_build }}" - apt: - name: "{{ haproxy_package }}" - update_cache: yes - register: haproxy_update - notify: Restart HAProxy - when: - - haproxy_package_name in ansible_facts.packages - - ansible_facts.packages[haproxy_package_name][0]['version'] != (haproxy_version|string + "-" + haproxy_version_build|string) +- name: Unmask HAProxy after install + ansible.builtin.systemd: + name: "{{ haproxy_unit_name }}" + masked: no + changed_when: false - name: Install python3-cryptography package: - name: python3-cryptography + name: python3-cryptography + state: present - block: - name: Check net.ipv4.ip_nonlocal_bind diff --git a/tasks/RedHat.yaml b/tasks/RedHat.yaml index 93d9b75..b2699bb 100644 --- a/tasks/RedHat.yaml +++ b/tasks/RedHat.yaml @@ -14,22 +14,14 @@ verbosity: 2 when: haproxy_installed_package is defined -- name: "Install {{ haproxy_package_name }}-{{ haproxy_version }}-{{ haproxy_version_build }}" +- name: "Install {{ haproxy_package }}" dnf: name: "{{ haproxy_package }}" + state: "{{ 'latest' if haproxy_version == 'latest' else 'present' }}" update_cache: yes register: haproxy_setup - when: haproxy_package_name not in ansible_facts.packages - -- name: "Update {{ haproxy_package_name }}-{{ haproxy_version }}-{{ haproxy_version_build }}" - dnf: - name: "{{ haproxy_package }}" - update_cache: yes - register: haproxy_update - notify: Restart HAProxy - when: - - haproxy_package_name in ansible_facts.packages - - (ansible_facts.packages[haproxy_package_name][0]['version'] + ".el" + ansible_distribution_major_version) != (haproxy_version|string + "-" + haproxy_version_build|string) + notify: + - Restart HAProxy - name: Install python2-cryptography package: @@ -44,7 +36,7 @@ name: python3-cryptography when: - ansible_facts['os_family'] == 'RedHat' - - ansible_facts['distribution_major_version'] == '8' or ansible_facts['distribution_major_version'] == '9' + - ansible_facts['distribution_major_version'] > '8' - haproxy_self_signed_cert - name: Set haproxy_connect_any flag on and keep it persistent across reboots @@ -131,7 +123,7 @@ - name: Enable and start HAProxy service systemd: - name: haproxy + name: "{{ haproxy_unit_name }}" state: started enabled: yes daemon_reload: yes diff --git a/vars/Debian-11.yaml b/vars/Debian-11.yaml deleted file mode 100644 index e9fc7c6..0000000 --- a/vars/Debian-11.yaml +++ /dev/null @@ -1,6 +0,0 @@ -haproxy_package_name: "haproxy" -haproxy_version: "2.6.12" -haproxy_version_build: "1~bpo11+1" -haproxy_package: "{{ haproxy_package_name }}={{ haproxy_version }}-{{ haproxy_version_build }}" -haproxy_package_name_regex: "{{ haproxy_package_name }}-{{ haproxy_version }}-{{ haproxy_version_build }}" -haproxy_unit_name: "{{ haproxy_package_name }}" diff --git a/vars/Debian-12.yaml b/vars/Debian-12.yaml deleted file mode 100644 index 68cbf5f..0000000 --- a/vars/Debian-12.yaml +++ /dev/null @@ -1,6 +0,0 @@ -haproxy_package_name: "haproxy" -haproxy_version: "2.6.12" -haproxy_version_build: "1+deb12u1" -haproxy_package: "{{ haproxy_package_name }}={{ haproxy_version }}-{{ haproxy_version_build }}" -haproxy_package_name_regex: "{{ haproxy_package_name }}-{{ haproxy_version }}-{{ haproxy_version_build }}" -haproxy_unit_name: "{{ haproxy_package_name }}" diff --git a/vars/Debian.yaml b/vars/Debian.yaml new file mode 100644 index 0000000..b94da11 --- /dev/null +++ b/vars/Debian.yaml @@ -0,0 +1,3 @@ +haproxy_package_name: "haproxy" +haproxy_package: "{{ haproxy_package_name + '=' + haproxy_version if (haproxy_version is defined and (haproxy_version != 'latest' and haproxy_version != '*' and haproxy_version != '')) else haproxy_package_name }}" +haproxy_unit_name: "{{ haproxy_package_name }}" diff --git a/vars/RedHat-8.yaml b/vars/RedHat-8.yaml deleted file mode 100644 index e04ca10..0000000 --- a/vars/RedHat-8.yaml +++ /dev/null @@ -1,7 +0,0 @@ -haproxy_package_name: "haproxy" -haproxy_version: "1.8.27" -haproxy_version_build: "5.el{{ ansible_distribution_major_version }}" -haproxy_package: "{{ haproxy_package_name }}-{{ haproxy_version }}-{{ haproxy_version_build }}" -haproxy_package_name_regex: "{{ haproxy_package_name }}-{{ haproxy_version }}-{{ haproxy_version_build }}" -haproxy_unit_name: "{{ haproxy_package_name }}" - diff --git a/vars/RedHat-9.yaml b/vars/RedHat-9.yaml deleted file mode 100644 index cde0b9d..0000000 --- a/vars/RedHat-9.yaml +++ /dev/null @@ -1,7 +0,0 @@ -haproxy_package_name: "haproxy" -haproxy_version: "2.4.22" -haproxy_version_build: "3.el{{ ansible_distribution_major_version }}" -haproxy_package: "{{ haproxy_package_name }}-{{ haproxy_version }}-{{ haproxy_version_build }}" -haproxy_package_name_regex: "{{ haproxy_package_name }}-{{ haproxy_version }}-{{ haproxy_version_build }}" -haproxy_unit_name: "{{ haproxy_package_name }}" - diff --git a/vars/RedHat.yaml b/vars/RedHat.yaml new file mode 100644 index 0000000..7306c0b --- /dev/null +++ b/vars/RedHat.yaml @@ -0,0 +1,4 @@ +haproxy_package_name: "haproxy" +haproxy_package: "{{ haproxy_package_name + '-' + haproxy_version if (haproxy_version is defined and (haproxy_version != 'latest' and haproxy_version != '*' and haproxy_version != '')) else haproxy_package_name }}" +haproxy_unit_name: "{{ haproxy_package_name }}" + diff --git a/vars/Ubuntu-20.04.yaml b/vars/Ubuntu-20.04.yaml deleted file mode 100644 index 1316519..0000000 --- a/vars/Ubuntu-20.04.yaml +++ /dev/null @@ -1,6 +0,0 @@ -haproxy_package_name: "haproxy" -haproxy_version: "2.0.33" -haproxy_version_build: "0ubuntu0.1" -haproxy_package: "{{ haproxy_package_name }}={{ haproxy_version }}-{{ haproxy_version_build }}" -haproxy_package_name_regex: "{{ haproxy_package_name }}-{{ haproxy_version }}-{{ haproxy_version_build }}" -haproxy_unit_name: "{{ haproxy_package_name }}" diff --git a/vars/Ubuntu-22.04.yaml b/vars/Ubuntu-22.04.yaml deleted file mode 100644 index 68b7b9a..0000000 --- a/vars/Ubuntu-22.04.yaml +++ /dev/null @@ -1,6 +0,0 @@ -haproxy_package_name: "haproxy" -haproxy_version: "2.4.24" -haproxy_version_build: "0ubuntu0.22.04.1" -haproxy_package: "{{ haproxy_package_name }}={{ haproxy_version }}-{{ haproxy_version_build }}" -haproxy_package_name_regex: "{{ haproxy_package_name }}-{{ haproxy_version }}-{{ haproxy_version_build }}" -haproxy_unit_name: "{{ haproxy_package_name }}"