Files
Leonidas Spyropoulos dd11d46206 mariadb: use PyMySQL and the ansible.mariadb collection
Switch to ansible.mariadb instead of the deprecated community.mysql

Signed-off-by: Leonidas Spyropoulos <artafinde@archlinux.org>
2026-09-08 17:14:47 +01:00

40 lines
1.2 KiB
YAML

- name: Install mariadb
pacman: name=mariadb,python-pymysql state=present
- name: Initialize mariadb
command: mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
args:
creates: /var/lib/mysql/mysql
- name: Configure mariadb
template: src=server.cnf.j2 dest=/etc/my.cnf.d/server.cnf owner=root group=root mode=0644
notify:
- Restart mariadb
- name: Start and enable the service
service: name=mariadb state=started enabled=yes
- name: Delete anonymous users
ansible.mariadb.mariadb_user: name='' host_all=yes state='absent'
- name: Disallow remote root login
command: 'mysql -NBe "{{ item }}"'
loop:
- DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1')
changed_when: false
- name: Drop test database
ansible.mariadb.mariadb_db: db=test state=absent
- name: Set root password
ansible.mariadb.mariadb_user: name=root host={{ item }} password={{ vault_mariadb_users.root }}
loop:
- '127.0.0.1'
- '::1'
- 'localhost'
no_log: true
- name: Create client configuration for root
template: src=client.cnf.j2 dest=/root/.my.cnf owner=root group=root mode=0644
no_log: true