Skip to content

Commit

Permalink
use Fully Qualified Collection Name (FQCN) ansible tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Iuga authored and eRadical committed Mar 3, 2024
1 parent 1267324 commit 1aa179d
Show file tree
Hide file tree
Showing 16 changed files with 80 additions and 80 deletions.
2 changes: 1 addition & 1 deletion handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
# handlers file for ansible-mariadb-galera-cluster
- name: "reload systemd daemon"
systemd:
ansible.builtin.systemd:
daemon_reload: true
become: true
4 changes: 2 additions & 2 deletions tasks/cacti.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: cacti_monitoring | adding cacti db user for monitoring
mysql_user:
community.mysql.mysql_user:
host: "{{ cacti_server }}"
login_unix_socket: "{{ mariadb_login_unix_socket | default(omit) }}"
name: "{{ cacti_db_user }}"
Expand All @@ -15,7 +15,7 @@
cacti_server is defined
- name: cacti_monitoring | adding cacti db user for monitoring
mysql_user:
community.mysql.mysql_user:
host: "{{ cacti_server_fqdn }}"
login_unix_socket: "{{ mariadb_login_unix_socket | default(omit) }}"
name: "{{ cacti_db_user }}"
Expand Down
12 changes: 6 additions & 6 deletions tasks/checks.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---

- name: ensure NIC specified in 'galera_cluster_bind_interface' exists
assert:
ansible.builtin.assert:
that: galera_cluster_bind_interface in ansible_interfaces
fail_msg: >-
The NIC name "{{ galera_cluster_bind_interface }}" specified in
Expand All @@ -12,7 +12,7 @@
- config

- name: When mariadb_sst_username is unix_socket, the mariadb_sst_password should not be set
assert:
ansible.builtin.assert:
that:
- mariadb_sst_password == ""
fail_msg: >-
Expand All @@ -24,7 +24,7 @@
- config

- name: When mariadb_sst_username is mysql_native_password, mariadb_sst_password should also be set
assert:
ansible.builtin.assert:
that:
- mariadb_sst_password != ""
fail_msg: >-
Expand All @@ -36,7 +36,7 @@
- config

- name: Check mariadb_version on target system
command: "mariadb -V"
ansible.builtin.command: "mariadb -V"
check_mode: false
register: mariadb_version_check
failed_when: '"mariadb" not in mariadb_version_check.stdout and mariadb_version_check.rc == 0'
Expand All @@ -56,12 +56,12 @@
- config

- name:
debug:
ansible.builtin.debug:
msg: "Installed {{ mariadb_version_checked }} - mariadb_version: {{ mariadb_version }}"
when: not mariadb_upgrade|bool and mariadb_version_check.rc == 0

- name: Verify the expected mariadb_version
assert:
ansible.builtin.assert:
that: 'mariadb_version_checked.startswith("{{ mariadb_version }}")'
fail_msg: >-
The mariadb_version "{{ mariadb_version }}" doesn't match the one
Expand Down
6 changes: 3 additions & 3 deletions tasks/configure_root_access.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: configure_root_access | updating root passwords
mysql_user:
community.mysql.mysql_user:
host: "{{ item }}"
login_unix_socket: "{{ mariadb_login_unix_socket | default(omit) }}"
name: "root"
Expand All @@ -18,7 +18,7 @@
- "localhost"

- name: configure_root_access | configuring root my.cnf
template:
ansible.builtin.template:
src: "root/my.cnf.j2"
dest: "/root/.my.cnf"
owner: "root"
Expand All @@ -28,7 +28,7 @@
no_log: true

- name: configure_root_access | updating root passwords (allow from anywhere)
mysql_user:
community.mysql.mysql_user:
host: "{{ item }}"
login_unix_socket: "{{ mariadb_login_unix_socket | default(omit) }}"
name: "root"
Expand Down
14 changes: 7 additions & 7 deletions tasks/debian.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
- name: debian | update package list
apt:
update_cache: yes
ansible.builtin.apt:
update_cache: true
cache_valid_time: 3600
become: true

- name: debian | installing pre-reqs
apt:
ansible.builtin.apt:
name: "{{ mariadb_pre_req_packages }}"
state: "present"
become: true
Expand All @@ -28,7 +28,7 @@
when: galera_enable_mariadb_repo|bool and mariadb_debian_repo_key_url is defined

- name: debian | pinning MariaDB Repo
template:
ansible.builtin.template:
src: "etc/apt/preferences.d/mariadb.j2"
dest: "/etc/apt/preferences.d/mariadb"
mode: "0644"
Expand All @@ -43,23 +43,23 @@
when: galera_enable_mariadb_repo|bool

- name: debian | precreate /etc/mysql/conf.d in case we need to add mariadb_config_overrides file
file:
ansible.builtin.file:
path: "/etc/mysql/conf.d"
state: "directory"
mode: 0755
become: true
when: mariadb_config_overrides is defined

- name: debian | add an overrides file
template:
ansible.builtin.template:
src: "etc/mariadb_overrides.cnf.j2"
dest: "/etc/mysql/conf.d/overrides.cnf"
mode: "0644"
become: true
when: mariadb_config_overrides is defined

- name: debian | installing mariadb-galera packages
apt:
ansible.builtin.apt:
name: "{{ (galera_sst_method == 'mariabackup') | ternary( mariadb_packages | union( mariabackup_packages ), mariadb_packages ) }}"
state: "present"
become: true
10 changes: 5 additions & 5 deletions tasks/galera_monitoring.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: galera_monitoring | configuring monitor script for galera
template:
ansible.builtin.template:
src: "etc/mysql/{{ galera_monitor_script_name }}.j2"
dest: "{{ galera_monitor_script_path }}/{{ galera_monitor_script_name }}"
owner: "mysql"
Expand All @@ -10,7 +10,7 @@
register: galera_monitoring_updated

- name: galera_monitoring | restarting mysql on first node
service:
ansible.builtin.service:
name: "{{ mariadb_systemd_service_name }}"
state: "restarted"
become: true
Expand All @@ -19,7 +19,7 @@
galera_monitoring_updated.changed
- name: galera_monitoring | waiting for mysql to start on first node
service:
ansible.builtin.service:
name: "{{ mariadb_systemd_service_name }}"
state: "started"
become: true
Expand All @@ -34,7 +34,7 @@
galera_monitoring_updated.changed
- name: galera_monitoring | restarting mysql on additional servers
service:
ansible.builtin.service:
name: "{{ mariadb_systemd_service_name }}"
state: "restarted"
become: true
Expand All @@ -44,7 +44,7 @@
galera_monitoring_updated.changed
- name: galera_monitoring | waiting for mysql to start on other nodes
service:
ansible.builtin.service:
name: "{{ mariadb_systemd_service_name }}"
state: "started"
become: true
Expand Down
24 changes: 12 additions & 12 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
# tasks file for ansible-mariadb-galera-cluster
- name: gather os specific variables
include_vars: "{{ item }}"
ansible.builtin.include_vars: "{{ item }}"
tags:
- always
- install
Expand All @@ -11,22 +11,22 @@
- "{{ ansible_distribution | lower }}.yml"
- "{{ ansible_os_family | lower }}.yml"

- import_tasks: checks.yml
- ansible.builtin.import_tasks: checks.yml
tags:
- always
- install

- import_tasks: debian.yml
- ansible.builtin.import_tasks: debian.yml
tags:
- install
when: ansible_os_family == "Debian"

- import_tasks: redhat.yml
- ansible.builtin.import_tasks: redhat.yml
tags:
- install
when: ansible_os_family == "RedHat"

- import_tasks: system_performance_tuning.yml
- ansible.builtin.import_tasks: system_performance_tuning.yml
tags:
- config

Expand All @@ -38,38 +38,38 @@

# ensure the first node is running in order to add users
- name: "ensure {{ mariadb_systemd_service_name }} is started on first node"
service:
ansible.builtin.service:
name: "{{ mariadb_systemd_service_name }}"
state: "started"
become: true
when: inventory_hostname == galera_mysql_first_node

- import_tasks: mysql_users.yml
- ansible.builtin.import_tasks: mysql_users.yml
tags:
- config
- mysql_users

- import_tasks: setup_cluster.yml
- ansible.builtin.import_tasks: setup_cluster.yml
tags:
- config

- import_tasks: configure_root_access.yml
- ansible.builtin.import_tasks: configure_root_access.yml
tags:
- config

- import_tasks: mysql_databases.yml
- ansible.builtin.import_tasks: mysql_databases.yml
tags:
- mysql_databases
when:
- mariadb_databases | count > 0
- inventory_hostname == galera_mysql_first_node

- import_tasks: galera_monitoring.yml
- ansible.builtin.import_tasks: galera_monitoring.yml
tags:
- config_galera_monitoring
when: galera_enable_galera_monitoring_script

- import_tasks: cacti.yml
- ansible.builtin.import_tasks: cacti.yml
tags:
- config_cacti_monitoring
when: galera_enable_cacti_monitoring
6 changes: 3 additions & 3 deletions tasks/manage_node_state.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: manage_node_state | make node systemd service {{ mariadb_systemd_service_state }}
service:
ansible.builtin.service:
name: "{{ mariadb_systemd_service_name }}"
state: "{{ mariadb_systemd_service_state }}"
become: true
Expand All @@ -16,7 +16,7 @@
- inventory_hostname == item

- name: manage_node_state | ensure node is fully stopped before continuing
service:
ansible.builtin.service:
name: "{{ mariadb_systemd_service_name }}"
state: "stopped"
become: true
Expand All @@ -29,7 +29,7 @@
- inventory_hostname == item

- name: manage_node_state | ensure node is fully started before continuing
service:
ansible.builtin.service:
name: "{{ mariadb_systemd_service_name }}"
state: "started"
become: true
Expand Down
4 changes: 2 additions & 2 deletions tasks/max-open-files.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
# Supplementary configuration file
- name: max-open-files | Create folder
file:
ansible.builtin.file:
path: "/etc/systemd/system/mariadb.service.d"
state: "directory"
owner: "root"
Expand All @@ -11,7 +11,7 @@
become: true

- name: max-open-files | Add the overriding file
template:
ansible.builtin.template:
src: "etc/systemd/system/mariadb.service.d/max-open-files.conf.j2"
dest: "/etc/systemd/system/mariadb.service.d/max-open-files.conf"
owner: "root"
Expand Down
8 changes: 4 additions & 4 deletions tasks/mysql_databases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# https://github.com/cdelgehier/ansible-role-XtraDB-Cluster/blob/master/tasks/postinstall.yml
# Many thanks to Cedric DELGEHIER
- name: mysql_databases | create the databases
mysql_db:
community.mysql.mysql_db:
name: "{{ item.name }}"
state: present
login_unix_socket: "{{ mariadb_login_unix_socket | default(omit) }}"
Expand All @@ -12,7 +12,7 @@
register: _db

- name: mysql_databases | copy database init scripts
copy:
ansible.builtin.copy:
src: "{{ item.item.init_script }}"
dest: "/tmp/{{ item.item.init_script | basename }}"
mode: "0600"
Expand All @@ -22,7 +22,7 @@
- item.item.init_script is defined

- name: mysql_databases | initialise databases
mysql_db:
community.mysql.mysql_db:
name: "{{ item.item.name }}"
state: import
target: "/tmp/{{ item.item.init_script | basename }}"
Expand All @@ -34,7 +34,7 @@
- item.item.init_script is defined

- name: mysql_databases | delete init scripts from the server
file:
ansible.builtin.file:
name: "/tmp/{{ item.item.init_script | basename }}"
state: absent
with_items: "{{ _db.results }}"
Expand Down
8 changes: 4 additions & 4 deletions tasks/mysql_users.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
- name: "Check if {{ mariadb_sst_username }} exists in the system"
block:
- name: "Check if {{ mariadb_sst_username }} exists in the system"
getent:
ansible.builtin.getent:
database: passwd
key: "{{ mariadb_sst_username }}"
ignore_errors: true
register: mariadb_sst_username__found
- name: Fail if the above user does not exist
fail:
ansible.builtin.fail:
msg: >-
The plugin for mariadb_sst_username was
set to unix_socket but the user does not exist.
Expand All @@ -19,7 +19,7 @@
when: mariadb_sst_user_plugin == "unix_socket"

- name: Create definition for mariadb_sst_user via unix_socket
set_fact:
ansible.builtin.set_fact:
mariadb_sst_user:
- name: "{{ mariadb_sst_username }}"
hosts:
Expand All @@ -31,7 +31,7 @@
when: mariadb_sst_user_plugin == "unix_socket"

- name: Create definition for mariadb_sst_user via mysql_native_password
set_fact:
ansible.builtin.set_fact:
mariadb_sst_user:
- name: "{{ mariadb_sst_username }}"
hosts:
Expand Down
Loading

0 comments on commit 1aa179d

Please sign in to comment.