From 500789c3c330045fc7085d5a94e6917a8570887f Mon Sep 17 00:00:00 2001 From: "flyingscorpio@clevo" Date: Mon, 7 Mar 2022 13:25:44 +0100 Subject: [PATCH] Add mariadb role --- configs.yml | 7 ------- playbook.yml | 1 + roles/mariadb/handlers/main.yml | 6 ++++++ roles/mariadb/meta/main.yml | 3 +++ roles/mariadb/tasks/main.yml | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 roles/mariadb/handlers/main.yml create mode 100644 roles/mariadb/meta/main.yml create mode 100644 roles/mariadb/tasks/main.yml diff --git a/configs.yml b/configs.yml index 65a9772..04c5198 100644 --- a/configs.yml +++ b/configs.yml @@ -11,13 +11,6 @@ etckeeper: - run: - sudo etckeeper commit "First commit" -mariadb: - - install: - - mariadb - - run: - command: sudo mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql && sudo systemctl start mysqld.service && sudo mysql_secure_installation - condition: "sudo find /var/lib/mysql -mindepth 1 | read" - rsync_backup: - run: - sudo ln -rsi dotfiles/systemd/rsync_backup.timer /etc/systemd/system/rsync_backup.timer diff --git a/playbook.yml b/playbook.yml index d02fa4b..4a86c9c 100644 --- a/playbook.yml +++ b/playbook.yml @@ -27,3 +27,4 @@ - { role: protonvpn, tags: protonvpn } - { role: repos, tags: repos } - { role: libvirt, tags: libvirt } + - { role: mariadb, tags: mariadb } diff --git a/roles/mariadb/handlers/main.yml b/roles/mariadb/handlers/main.yml new file mode 100644 index 0000000..2e40784 --- /dev/null +++ b/roles/mariadb/handlers/main.yml @@ -0,0 +1,6 @@ +--- +- name: Start mysqld service + systemd: + name: mysqld + state: started + scope: system diff --git a/roles/mariadb/meta/main.yml b/roles/mariadb/meta/main.yml new file mode 100644 index 0000000..edef5f0 --- /dev/null +++ b/roles/mariadb/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - role: check-sudo diff --git a/roles/mariadb/tasks/main.yml b/roles/mariadb/tasks/main.yml new file mode 100644 index 0000000..af8186b --- /dev/null +++ b/roles/mariadb/tasks/main.yml @@ -0,0 +1,32 @@ +--- +- name: Install mariadb (Archlinux) + become: true + pacman: + name: + - mariadb + when: ansible_distribution == 'Archlinux' + +- name: Install mariadb (Debian) + become: true + apt: + name: + - mariadb + when: ansible_distribution == 'Debian' + +- name: Initialize mariadb + become: true + command: mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql + register: result + changed_when: "'table already exists!' not in result.stdout" + notify: Start mysqld service + +- name: Secure the installation + become: true + command: mysql_secure_installation + when: "'table already exists!' not in result.stdout" + +- name: Stop mysqld service + systemd: + name: mysqld + state: stopped + scope: system