Skip to content
Snippets Groups Projects
Commit 900ac8e8 authored by Chris Croome's avatar Chris Croome
Browse files

Debug test

parent 93f62bc5
No related branches found
No related tags found
No related merge requests found
Pipeline #20825 passed
---
# The mariadb variable needs to be true for the tasks in this role to be run
mariadb: true
mariadb_host: localhost
mariadb_port: 3360
# The mariadb_path is used as a test for the local facts
mariadb_path: /usr/bin/mariadb
mariadb_socket: /var/run/mysqld/mysqld.sock
# To use community.mysql modules set mariadb_community to true
# https://docs.ansible.com/ansible/latest/collections/community/mysql/index.html
mariadb_community: true
# If mariadb_sys_schema is true then the sys schema is imported from this repo
# https://github.com/webarch-coop/mariadb-sys
mariadb_sys_schema: true
# Systemd security settings
# https://mariadb.com/kb/en/library/systemd/
......
---
- name: Ansible MariaDB local facts
block:
......@@ -28,12 +29,12 @@
- name: Re-read Ansible local facts
ansible.builtin.setup:
filter: ansible_local
when: mariadb_root_fact.changed
when: mariadb_root_fact.changed
- name: Print Ansible MariaDB root plugin local facts
debug:
msg: "{{ ansible_local.mariadb_root }}"
verbosity: 2
verbosity: 3
- name: Tasks when Ansible MariaDB root plugin local facts successful
block:
......
......@@ -25,14 +25,17 @@
- name: Include local facts tasks
include_tasks: local_facts.yml
- name: Query the MariaDB databases, users and version using a socket
include_tasks: info.yml
when:
- name: Query the MariaDB databases, users and version using a password and the command module
include_tasks: info_password.yml
when:
- ansible_local.mariadb_root.state == "present"
- ansible_local.mariadb_root.plugin is regex('^auth_socket|unix_socket$')
- ansible_local.mariadb_root.plugin == "mysql_native_password"
- name: Debug fail
fail:
- name: Query the MariaDB databases, users and version using a socket and the community.mysql.mysql_info module
include_tasks: info_socket.yml
when:
- ansible_local.mariadb_root.state == "present"
- ansible_local.mariadb_root.plugin is regex('^auth_socket|unix_socket$')
- name: MariaDB server defaults in place
ansible.builtin.template:
......@@ -80,7 +83,7 @@
- name: Include the MariaDB sys schema tasks
ansible.builtin.include_tasks: sys.yml
when: ( "sys" not in mariadb_databases )
when: ( mariadb_sys_schema ) and ( "sys" not in mariadb_databases )
- name: Run mysql_upgrade
ansible.builtin.command: mysql_upgrade
......
......@@ -15,38 +15,30 @@
clone: true
version: master
# - name: Use shell to import the MariaDB sys schema
# block:
# # Bash might be /bin/bash or /usr/bin/bash
# - name: Run which bash
# ansible.builtin.command: which bash
# check_mode: false
# changed_when: false
# register: which_bash
# failed_when: which_bash.stdout is not regex('\/bash$')
# - name: Set a variable for the path to Bash
# ansible.builtin.set_fact:
# bash: "{{ which_bash.stdout }}"
# - name: Import the sys schema
# ansible.builtin.shell: |
# set -e -o pipefail
# mysql < ./mariadb_sys_install.sql
# args:
# executable: "{{ bash }}"
# chdir: /usr/local/src/mariadb-sys
# when: not mariadb_community
- name: Use import the sys schema using credentials from /root/.my.cnf
community.mysql.mysql_db:
name: all
target: /usr/local/src/mariadb-sys/mariadb_sys_install.sql
login_user: root
config_file: /root/.my.cnf
when: mariadb_root_auth_current == "mysql_native_password"
- name: Use shell to import the MariaDB sys schema
block:
# Bash might be /bin/bash or /usr/bin/bash
- name: Run which bash
ansible.builtin.command: which bash
check_mode: false
changed_when: false
register: which_bash
failed_when: which_bash.stdout is not regex('\/bash$')
- name: Set a variable for the path to Bash
ansible.builtin.set_fact:
bash: "{{ which_bash.stdout }}"
- name: Import the sys schema
ansible.builtin.shell: |
set -e -o pipefail
mysql < ./mariadb_sys_install.sql
args:
executable: "{{ bash }}"
chdir: /usr/local/src/mariadb-sys
when: ansible_local.mariadb_root.plugin == "mysql_native_password"
- name: Use import the sys schema using unix_socket
community.mysql.mysql_db:
......@@ -54,7 +46,7 @@
target: /usr/local/src/mariadb-sys/mariadb_sys_install.sql
login_user: root
login_unix_socket: /run/mysqld/mysqld.sock
when: mariadb_root_auth_current == "unix_socket"
when: ansible_local.mariadb_root.plugin is regex('^auth_socket|unix_socket$')
tags:
- mariadb
......
......@@ -2,11 +2,26 @@
# {{ ansible_managed }}
set -euo pipefail
MARIADB="{{ mariadb_path }}"
MARIADB_HOST="{{ mariadb_host }}"
MARIADB_PORT="{{ mariadb_port }}"
if [[ -f "${MARIADB}" ]]; then
PLUGIN=$("${MARIADB}" -BNe "SELECT plugin FROM user WHERE User='root'" mysql)
jo state=present plugin="${PLUGIN}"
PLUGIN=$("${MARIADB}" -h "${MARIADB_HOST}" -P "${MARIADB_PORT}" -BNe "SELECT plugin FROM user WHERE Host='${MARIADB_HOST}' User='root'" mysql)
NO=$(echo "${PLUGIN}" | wc -l)
if [[ "${NO}" eq "1" ]]; then
jo state=present plugin="${PLUGIN}"
elif [[ "${NO}" gt "1" ]]; then
PLUGINS=$( echo "${PLUGIN}" | xargs)
jo state=present -a plugin=$(jo -a "${PLUGINS}")
else
echo "Sorry $0 was unable to find the MariaDB root authentication plugin(s)"
echo 1
fi
else
jo state=absent
fi
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment