From a5bea0c63179bdf2ba1c55bf90245424cdf43152 Mon Sep 17 00:00:00 2001 From: Dmitriy Rabotyagov Date: Fri, 3 Jul 2020 00:55:02 +0300 Subject: [PATCH] Add support for wider distro set This patch makes pacemaker/corosync more universal, and now it's possbile to use role against CentOS 7 and CentOS 8 --- README.md | 2 +- handlers/main.yml | 1 + tasks/pacemaker.yml | 54 ++++++++++++++++++++------------------ templates/corosync.conf.j2 | 2 +- 4 files changed, 31 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 56fb970..fc4034d 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ ansible-pacemaker-corosync role =============================== -Deploys corosync/pacemaker on Ubuntu 14.04 +Deploys corosync/pacemaker # Variables diff --git a/handlers/main.yml b/handlers/main.yml index 10a59be..7c3e314 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -2,6 +2,7 @@ service: name: "{{ item }}" state: restarted + enabled: yes with_items: - corosync - pacemaker diff --git a/tasks/pacemaker.yml b/tasks/pacemaker.yml index 9f229f2..2420ce8 100644 --- a/tasks/pacemaker.yml +++ b/tasks/pacemaker.yml @@ -1,12 +1,23 @@ +- name: Enable HighAvailability repository + command: yum-config-manager --enable HighAvailability + changed_when: false + when: + - ansible_os_family | lower == 'redhat' + - ansible_distribution_major_version is version('8', '=') + - name: Installs pacemaker & corosync - apt: pkg={{item}} state=present + package: + name: "{{ item }}" + state: present with_items: - corosync - pacemaker - name: Install haveged - apt: pkg=haveged state=present - when: haveged_enabled | default(true) + package: + name: haveged + state: present + when: haveged_enabled | default(True) | bool - name: Generates corosync key become: true @@ -19,21 +30,28 @@ notify: Restart corosync - name: Generate tmpdir for authkey - local_action: tempfile + local_action: + module: tempfile register: authkey_tempfile changed_when: False check_mode: no when: inventory_hostname != groups[pacemaker_corosync_group][0] - name: Fetch authkey for other nodes - fetch: src=/etc/corosync/authkey dest="{{ authkey_tempfile.path }}" flat=yes + fetch: + src: /etc/corosync/authkey + dest: "{{ authkey_tempfile.path }}" + flat: yes delegate_to: "{{ groups[pacemaker_corosync_group][0] }}" changed_when: False check_mode: no when: inventory_hostname != groups[pacemaker_corosync_group][0] - name: Copy authkey to other nodes - copy: src="{{ authkey_tempfile.path }}" dest=/etc/corosync/authkey mode=0400 + copy: + src: "{{ authkey_tempfile.path }}" + dest: /etc/corosync/authkey + mode: "0400" when: inventory_hostname != groups[pacemaker_corosync_group][0] notify: Restart corosync @@ -49,7 +67,7 @@ - name: Chowns authkeys file: path: /etc/corosync/authkey - mode: 0400 + mode: "0400" owner: root notify: Restart corosync @@ -57,7 +75,7 @@ template: src: corosync.conf.j2 dest: /etc/corosync/corosync.conf - mode: 0400 + mode: "0400" owner: root notify: Restart corosync @@ -65,7 +83,7 @@ template: src: corosync_logrotate.conf.j2 dest: /etc/logrotate.d/corosync - mode: 0644 + mode: "0644" owner: root - name: Creates services directory @@ -78,7 +96,7 @@ src: pcmk dest: /etc/corosync/service.d/pcmk owner: root - mode: 0400 + mode: "0400" notify: Restart corosync - name: Adds ferm filtering @@ -88,19 +106,3 @@ when: ferm_enabled | default(false) tags: ferm notify: Restart ferm - -- name: Enables corosync at boot - copy: - dest: /etc/default/corosync - content: "START=yes" - when: ansible_service_mgr != "systemd" - -- name: Enables corosync at boot - systemd: name=corosync.service state=started enabled=yes - when: ansible_service_mgr == "systemd" - -- name: Registers pacemaker service - service: - name: pacemaker - enabled: true - diff --git a/templates/corosync.conf.j2 b/templates/corosync.conf.j2 index 3293f3b..e212057 100644 --- a/templates/corosync.conf.j2 +++ b/templates/corosync.conf.j2 @@ -6,7 +6,7 @@ totem { {% endif %} interface { ringnumber: 0 - bindnetaddr: {{ hostvars[inventory_hostname]['ansible_' + pacemaker_corosync_ring_interface].ipv4.address }} + bindnetaddr: {{ hostvars[inventory_hostname]['ansible_' + pacemaker_corosync_ring_interface | replace('-', '_')].ipv4.address }} broadcast: yes mcastport: 5405 }