From 5841e55a45ca43a39e42d73ea6b1a95faa3da254 Mon Sep 17 00:00:00 2001 From: Emilien Mantel Date: Mon, 26 Aug 2024 10:12:09 +0200 Subject: [PATCH] :rotating_light: Fix modernized linter --- handlers/main.yml | 2 +- meta/main.yml | 4 +-- tasks/galera/bootstrap.yml | 7 +++-- tasks/galera/nodes.yml | 42 ++++++++++++------------- tasks/install/mariadb/upstream.yml | 17 +++------- tasks/replication/master.yml | 2 +- tasks/replication/slave.yml | 6 ++-- tasks/replication/slave/import_data.yml | 10 +++--- tasks/replication/slave/replication.yml | 8 ++--- tasks/secure.yml | 4 +-- 10 files changed, 48 insertions(+), 54 deletions(-) diff --git a/handlers/main.yml b/handlers/main.yml index 3b0c2ba..424bf17 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,6 +1,6 @@ --- -- name: restart mariadb +- name: Restart mariadb ansible.builtin.service: name: "{{ mariadb_service_name }}" state: restarted diff --git a/meta/main.yml b/meta/main.yml index 7c55335..b14d621 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -5,9 +5,9 @@ galaxy_info: role_name: mysql author: Emilien Mantel description: Install and configure MariaDB (and Galera Cluster) on Debian - company: + company: TripleStack license: GPLv2 - min_ansible_version: 2.11 + min_ansible_version: '2.11' platforms: - name: Debian versions: diff --git a/tasks/galera/bootstrap.yml b/tasks/galera/bootstrap.yml index e9bfd2a..011a892 100644 --- a/tasks/galera/bootstrap.yml +++ b/tasks/galera/bootstrap.yml @@ -8,7 +8,9 @@ path: "{{ __mark }}" register: s -- block: +- name: COMMAND | Setup galera cluster + when: not s.stat.exists or mariadb_galera_resetup + block: - name: SET_FACT | We must NOT restart after bootstrap! ansible.builtin.set_fact: mariadb_notify_restart: false @@ -21,6 +23,7 @@ - name: COMMAND | Bootstrap first node (systemd) ansible.builtin.command: galera_new_cluster when: ansible_service_mgr == 'systemd' + changed_when: true - name: SERVICE | Bootstrap first node (clean init) ansible.builtin.service: @@ -30,8 +33,6 @@ register: bootstrap_run when: ansible_service_mgr != 'systemd' - when: not s.stat.exists or mariadb_galera_resetup - - name: COMMAND | Create Bootstrap mark ansible.builtin.command: "touch {{ __mark }}" args: diff --git a/tasks/galera/nodes.yml b/tasks/galera/nodes.yml index c84f697..71f232b 100644 --- a/tasks/galera/nodes.yml +++ b/tasks/galera/nodes.yml @@ -11,25 +11,25 @@ register: ondc changed_when: false -- block: - - - name: SERVICE | Stop MariaDB - ansible.builtin.service: - name: "{{ mariadb_service_name }}" - state: stopped - - - name: COPY | Paste primary node's debian.cnf - ansible.builtin.copy: - content: "{{ debiancnf.stdout }}" - dest: /etc/mysql/debian.cnf - mode: 0600 - owner: root - group: root - register: paste - - - name: SERVICE | Start MariaDB - ansible.builtin.service: - name: "{{ mariadb_service_name }}" - state: started - +- name: BLOCK | Compare debian.cnf when: debiancnf.stdout != ondc.stdout + block: + + - name: SERVICE | Stop MariaDB + ansible.builtin.service: + name: "{{ mariadb_service_name }}" + state: stopped + + - name: COPY | Paste primary node's debian.cnf + ansible.builtin.copy: + content: "{{ debiancnf.stdout }}" + dest: /etc/mysql/debian.cnf + mode: 0600 + owner: root + group: root + register: paste + + - name: SERVICE | Start MariaDB + ansible.builtin.service: + name: "{{ mariadb_service_name }}" + state: started diff --git a/tasks/install/mariadb/upstream.yml b/tasks/install/mariadb/upstream.yml index 0417ba1..c8638c4 100644 --- a/tasks/install/mariadb/upstream.yml +++ b/tasks/install/mariadb/upstream.yml @@ -4,13 +4,15 @@ ansible.builtin.apt: name: gpg -- name: COMMAND | Check indempotent +- name: COMMAND | Check expected mariadb version ansible.builtin.command: 'grep -q "{{ mariadb_upstream_version }}" /etc/apt/sources.list.d/mariadb.list' - register: check_idempotent + register: check_version failed_when: false changed_when: false -- block: +- name: APT | Add MariaDB upstream repository + when: check_version.rc > 0 + block: - name: GET_URL | Download MariaDB setup script ansible.builtin.get_url: @@ -28,12 +30,3 @@ ansible.builtin.file: path: '/tmp/mariadb_repo_setup' state: absent - - when: check_idempotent.rc > 0 - -- name: SHELL | Remove useless old files - ansible.builtin.shell: 'rm -f /etc/apt/sources.list.d/mariadb.list.old_*' - args: - removes: /etc/apt/sources.list.d/mariadb.list.old_1 - tags: - - skip_ansible_lint diff --git a/tasks/replication/master.yml b/tasks/replication/master.yml index 04b11c9..5316a22 100644 --- a/tasks/replication/master.yml +++ b/tasks/replication/master.yml @@ -7,4 +7,4 @@ mode: 0644 owner: root group: root - notify: restart mariadb + notify: Restart mariadb diff --git a/tasks/replication/slave.yml b/tasks/replication/slave.yml index fdc954e..1c2924e 100644 --- a/tasks/replication/slave.yml +++ b/tasks/replication/slave.yml @@ -14,11 +14,11 @@ mode: 0644 owner: root group: root - notify: restart mariadb + notify: Restart mariadb - name: MYSQL_REPLICATION | Get slave status community.mysql.mysql_replication: - mode: getslave + mode: getreplica login_unix_socket: "{{ mariadb_socket }}" ignore_errors: true register: slave_status @@ -33,7 +33,7 @@ - name: MYSQL_REPLICATION | Get slave status community.mysql.mysql_replication: - mode: getslave + mode: getreplica login_unix_socket: "{{ mariadb_socket }}" ignore_errors: true register: slave_status diff --git a/tasks/replication/slave/import_data.yml b/tasks/replication/slave/import_data.yml index 301c558..7c22a33 100644 --- a/tasks/replication/slave/import_data.yml +++ b/tasks/replication/slave/import_data.yml @@ -7,11 +7,13 @@ mode: 0700 - name: OPENSSH_KEYPAIR | Create SSH key - openssh_keypair: + community.crypto.openssh_keypair: path: "{{ ansible_env.HOME }}/.ssh/id_rsa" register: gen_ssh -- block: +- name: BLOCK | Prepare backup + delegate_to: "{{ mariadb_slave_import_from }}" + block: - name: AUTHORIZED_KEY | Auth slave to backup host ansible.posix.authorized_key: @@ -33,14 +35,12 @@ creates: "{{ mariadb_backup_dir }}/xtrabackup_info" register: backup - - name: COMMAND | Dump + - name: COMMAND | Dump # noqa: no-handler ansible.builtin.command: "mariabackup --prepare --target-dir={{ mariadb_backup_dir }}" when: backup.changed register: prep changed_when: "'This target seems to be not prepared yet' in prep.stderr" - delegate_to: "{{ mariadb_slave_import_from }}" - - name: MYSQL_VARIABLES | Get datadir community.mysql.mysql_variables: variable: datadir diff --git a/tasks/replication/slave/replication.yml b/tasks/replication/slave/replication.yml index 2bd9fd8..0295952 100644 --- a/tasks/replication/slave/replication.yml +++ b/tasks/replication/slave/replication.yml @@ -1,12 +1,12 @@ --- - name: MYSQL_REPLICATION | Stop slave - mysql_replication: + community.mysql.mysql_replication: mode: stopslave login_unix_socket: "{{ mariadb_socket }}" - name: MYSQL_REPLICATION | Configure master host - mysql_replication: + community.mysql.mysql_replication: mode: changemaster master_host: "{{ mariadb_replication_host }}" master_port: "{{ mariadb_replication_port }}" @@ -16,7 +16,7 @@ no_log: "{{ not mariadb_debug_role }}" - name: MYSQL_REPLICATION | Change master - mysql_replication: + community.mysql.mysql_replication: mode: changemaster master_log_file: "{{ mariadb_master_log_file }}" master_log_pos: "{{ mariadb_master_log_pos }}" @@ -24,6 +24,6 @@ when: mariadb_master_log_file is defined and mariadb_master_log_pos is defined - name: MYSQL_REPLICATION | Start slave - mysql_replication: + community.mysql.mysql_replication: mode: startslave login_unix_socket: "{{ mariadb_socket }}" diff --git a/tasks/secure.yml b/tasks/secure.yml index cda139f..224ae15 100644 --- a/tasks/secure.yml +++ b/tasks/secure.yml @@ -1,7 +1,7 @@ --- - name: MYSQL_USER | Remove all anonymous users - mysql_user: + community.mysql.mysql_user: name: '' host: "{{ item }}" state: absent @@ -13,7 +13,7 @@ - localhost - name: MYSQL_DB | Remove the test database - mysql_db: + community.mysql.mysql_db: name: test state: absent login_unix_socket: "{{ mariadb_socket }}"