From e81de8a9ff196d96f7c049eb89cc28ba68ac411e Mon Sep 17 00:00:00 2001 From: Timo Makinen Date: Wed, 25 Aug 2021 19:30:39 +0000 Subject: [PATCH] mariadb: Add support for setting root password --- roles/mariadb/tasks/main.yml | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/roles/mariadb/tasks/main.yml b/roles/mariadb/tasks/main.yml index 097291b..cced584 100644 --- a/roles/mariadb/tasks/main.yml +++ b/roles/mariadb/tasks/main.yml @@ -1,8 +1,11 @@ --- - name: install packages package: - name: mariadb-server + name: "{{ item }}" state: installed + with_items: + - mariadb-server + - python3-PyMySQL - name: fix selinux contexts from data directory sefcontext: @@ -56,3 +59,23 @@ name: mariadb state: started enabled: true + +- name: set root password + mysql_user: + name: root + password: "{{ mariadb_root_password }}" + login_user: root + login_password: "{{ mariadb_root_password }}" + check_implicit_admin: true + login_unix_socket: /var/lib/mysql/mysql.sock + no_log: true + when: mariadb_root_password is defined + +- name: create root .my.cnf + template: + dest: /root/.my.cnf + src: my.cnf.j2 + mode: 0600 + owner: root + group: "{{ ansible_wheel }}" + when: mariadb_root_password is defined