--- - name: Check if the specified root password is already set ansible.builtin.shell: > mysqladmin -u root status changed_when: false failed_when: false no_log: true become: true ignore_errors: true register: _mariadb_password_check tags: mariadb - name: Change the root password community.mysql.mysql_user: name: "root" host: "localhost" password: "{{ mariadb_root_password }}" login_unix_socket: "{{ mariadb_unix_socket }}" no_log: true run_once: true when: _mariadb_password_check.rc == 0 tags: root_password - name: Create /root/.my.cnf ansible.builtin.copy: dest: "/root/.my.cnf" mode: "0640" owner: root group: root content: | [client] user=root password={{ mariadb_root_password}} become: true when: - mariadb_root_password is defined and mariadb_root_password != "" - mariadb_create_root_my_cnf is defined and mariadb_create_root_my_cnf no_log: true # code: language=ansible