2014-08-16 23:35:57 +02:00
|
|
|
---
|
2022-09-12 09:09:41 +02:00
|
|
|
- name: Remove MariaDB key from apt-key
|
|
|
|
ansible.builtin.apt_key:
|
|
|
|
id: 0x177F4010FE56CA3336300305F1656F24C74CD1D8
|
|
|
|
state: absent
|
|
|
|
tags:
|
|
|
|
- packages
|
|
|
|
- mariadb
|
|
|
|
|
|
|
|
- name: Check MariaDB package signing key
|
|
|
|
ansible.builtin.stat:
|
|
|
|
path: /etc/apt/keyrings/mariadb_release_signing_key.asc
|
|
|
|
register: mariadb_signing_key_stat
|
|
|
|
tags:
|
|
|
|
- packages
|
|
|
|
- mariadb
|
|
|
|
|
|
|
|
- name: Download MariaDB package signing key
|
|
|
|
ansible.builtin.get_url:
|
|
|
|
url: https://mariadb.org/mariadb_release_signing_key.asc
|
|
|
|
dest: /etc/apt/keyrings/mariadb_release_signing_key.asc
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: 0644
|
|
|
|
register: download_mariadb_signing_key
|
|
|
|
when: not mariadb_signing_key_stat.stat.exists
|
|
|
|
tags:
|
|
|
|
- packages
|
|
|
|
- mariadb
|
2014-08-16 23:35:57 +02:00
|
|
|
|
2022-09-12 08:25:46 +02:00
|
|
|
- name: Add MariaDB 10.6 repo
|
2022-09-12 09:09:41 +02:00
|
|
|
ansible.builtin.apt_repository:
|
|
|
|
repo: 'deb [arch=amd64 signed-by=/etc/apt/keyrings/mariadb_release_signing_key.asc] https://dlm.mariadb.com/repo/mariadb-server/10.6/repo/debian {{ ansible_distribution_release }} main'
|
|
|
|
filename: mariadb
|
|
|
|
state: present
|
2019-03-17 16:29:15 +01:00
|
|
|
register: add_mariadb_apt_repository
|
2022-09-12 09:09:41 +02:00
|
|
|
tags:
|
|
|
|
- packages
|
|
|
|
- mariadb
|
2014-08-16 23:35:57 +02:00
|
|
|
|
2019-03-17 16:29:15 +01:00
|
|
|
- name: Update apt cache
|
2022-09-12 09:09:41 +02:00
|
|
|
ansible.builtin.apt: # noqa no-handler
|
2022-09-10 21:33:19 +02:00
|
|
|
update_cache: true
|
2019-03-17 16:29:15 +01:00
|
|
|
when:
|
2022-09-12 09:09:41 +02:00
|
|
|
(download_mariadb_signing_key.status_code is defined and download_mariadb_signing_key.status_code == 200) or
|
2019-03-17 16:29:15 +01:00
|
|
|
add_mariadb_apt_repository is changed
|
2022-09-12 09:09:41 +02:00
|
|
|
tags:
|
|
|
|
- packages
|
|
|
|
- mariadb
|
2019-03-17 16:29:15 +01:00
|
|
|
|
2014-08-16 23:35:57 +02:00
|
|
|
- name: Install mariadb-server
|
2022-09-12 09:12:07 +02:00
|
|
|
ansible.builtin.apt:
|
|
|
|
name: ['mariadb-server', 'python3-pymysql']
|
|
|
|
state: present
|
|
|
|
cache_valid_time: 3600
|
2016-08-14 15:33:48 +02:00
|
|
|
tags: mariadb, packages
|
2014-08-16 23:35:57 +02:00
|
|
|
|
2016-04-22 09:08:32 +02:00
|
|
|
- name: Create system my.cnf
|
2022-09-12 09:16:42 +02:00
|
|
|
ansible.builtin.template:
|
|
|
|
src: my.cnf.j2
|
|
|
|
dest: /etc/mysql/my.cnf
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: 0644
|
2016-04-22 09:08:32 +02:00
|
|
|
notify:
|
2020-12-29 10:25:30 +01:00
|
|
|
- restart mariadb
|
2016-04-22 09:08:32 +02:00
|
|
|
tags: mariadb
|
|
|
|
|
2021-09-07 15:47:47 +02:00
|
|
|
# See: https://docs.ansible.com/ansible/latest/collections/community/mysql/mysql_user_module.html
|
2014-08-16 23:35:57 +02:00
|
|
|
- name: Update MariaDB root password for all root accounts
|
2022-09-12 09:16:42 +02:00
|
|
|
community.mysql.mysql_user:
|
|
|
|
name: root
|
|
|
|
host: "{{ item }}"
|
|
|
|
password: "{{ mariadb_root_password }}"
|
|
|
|
login_unix_socket: "{{ mariadb_login_unix_socket }}"
|
2018-04-02 14:52:51 +02:00
|
|
|
loop:
|
2014-08-16 23:35:57 +02:00
|
|
|
- 127.0.0.1
|
|
|
|
- ::1
|
|
|
|
tags: mariadb
|
|
|
|
|
|
|
|
- name: Create .my.conf file with root credentials
|
2022-09-12 09:16:42 +02:00
|
|
|
ansible.builtin.template:
|
|
|
|
src: .my.cnf.j2
|
|
|
|
dest: /root/.my.cnf
|
|
|
|
owner: root
|
|
|
|
mode: 0600
|
2014-08-16 23:35:57 +02:00
|
|
|
tags: mariadb
|
|
|
|
|
2021-09-07 15:47:47 +02:00
|
|
|
# See: https://docs.ansible.com/ansible/latest/collections/community/mysql/mysql_db_module.html
|
2016-06-27 17:08:02 +02:00
|
|
|
- name: Create MariaDB database(s)
|
2022-09-12 09:16:42 +02:00
|
|
|
community.mysql.mysql_db:
|
|
|
|
db: "{{ item.name }}"
|
|
|
|
state: present
|
|
|
|
encoding: utf8mb4
|
|
|
|
login_unix_socket: "{{ mariadb_login_unix_socket }}"
|
2018-04-02 14:52:51 +02:00
|
|
|
loop: "{{ mariadb_databases }}"
|
2016-06-27 17:08:02 +02:00
|
|
|
when: mariadb_databases is defined
|
2014-08-28 11:47:30 +02:00
|
|
|
tags: mariadb
|
|
|
|
|
2016-06-27 17:08:02 +02:00
|
|
|
- name: Create MariaDB user(s)
|
2022-09-12 09:16:42 +02:00
|
|
|
community.mysql.mysql_user:
|
|
|
|
name: "{{ item.user }}"
|
|
|
|
password: "{{ item.pass }}"
|
|
|
|
priv: "{{ item.name }}.*:ALL"
|
|
|
|
host: 127.0.0.1
|
|
|
|
state: present
|
|
|
|
login_unix_socket: "{{ mariadb_login_unix_socket }}"
|
2018-04-02 14:52:51 +02:00
|
|
|
loop: "{{ mariadb_databases }}"
|
2016-06-27 17:08:02 +02:00
|
|
|
when: mariadb_databases is defined
|
2014-08-28 11:47:30 +02:00
|
|
|
tags: mariadb
|
|
|
|
|
2014-08-16 23:35:57 +02:00
|
|
|
# vim: set ts=2 sw=2:
|