setup-cockpit/roles/mariadb/tasks/main.yml

63 lines
1.6 KiB
YAML

---
- name: Install mariadb (Archlinux)
become: true
community.general.pacman:
name:
- mariadb
- python-pymysql
when: ansible_facts['distribution'] == 'Archlinux'
- name: Install mariadb (Debian)
become: true
ansible.builtin.apt:
name:
- mariadb-server
- python3-pymysql
when: ansible_facts['distribution'] == 'Debian'
- name: Initialize mariadb
become: true
ansible.builtin.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
when: "'table already exists!' not in result.stdout"
block:
- name: Set root password
community.mysql.mysql_user:
user: root
password: ""
host: localhost
no_log: true
- name: Remove anonymous user for ansible_fqdn
community.mysql.mysql_user:
user: ""
host: "{{ ansible_fqdn }}"
state: absent
- name: Remove anonymous user for localhost
community.mysql.mysql_user:
user: ""
state: absent
- name: Remove remote root access
community.mysql.mysql_user:
user: root
password: ""
host: "{{ item }}"
no_log: true
with_items:
- "::1"
- "127.0.0.1"
- localhost
- name: Remove test database
community.mysql.mysql_db:
db: test
state: absent
- name: Stop mysqld service
ansible.builtin.systemd:
name: mysqld
state: stopped
scope: system