Does something like this work?
- name: Update MySQL root password
community.mysql.mysql_user:
name: "{{ db_user }}"
password: "{{ db_pass }}"
login_user: root
config_file: /root/.my.cnf
register: root_user
- name: Debug root_user
ansible.builtin.debug:
var: root_user
Note that once you change the root
password you will also need to update the /root/.my.cnf
file, you can use the ini_file module for this since MySQL configuration files use the INI format.