--- - 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 - name: Add MariaDB 10.6 repo 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 register: add_mariadb_apt_repository tags: - packages - mariadb - name: Update apt cache ansible.builtin.apt: # noqa no-handler update_cache: true when: (download_mariadb_signing_key.status_code is defined and download_mariadb_signing_key.status_code == 200) or add_mariadb_apt_repository is changed tags: - packages - mariadb - name: Install mariadb-server ansible.builtin.apt: name: ['mariadb-server', 'python3-pymysql'] state: present cache_valid_time: 3600 tags: mariadb, packages - name: Create system my.cnf ansible.builtin.template: src=my.cnf.j2 dest=/etc/mysql/my.cnf owner=root group=root mode=0644 notify: - restart mariadb tags: mariadb # See: https://docs.ansible.com/ansible/latest/collections/community/mysql/mysql_user_module.html - name: Update MariaDB root password for all root accounts community.mysql.mysql_user: name=root host={{ item }} password={{ mariadb_root_password }} login_unix_socket={{ mariadb_login_unix_socket }} loop: - 127.0.0.1 - ::1 tags: mariadb - name: Create .my.conf file with root credentials ansible.builtin.template: src=.my.cnf.j2 dest=/root/.my.cnf owner=root mode=0600 tags: mariadb # See: https://docs.ansible.com/ansible/latest/collections/community/mysql/mysql_db_module.html - name: Create MariaDB database(s) community.mysql.mysql_db: db={{ item.name }} state=present encoding=utf8mb4 login_unix_socket={{ mariadb_login_unix_socket }} loop: "{{ mariadb_databases }}" when: mariadb_databases is defined tags: mariadb - name: Create MariaDB user(s) 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 }} loop: "{{ mariadb_databases }}" when: mariadb_databases is defined tags: mariadb # vim: set ts=2 sw=2: