Issue
I can't setup MySQL root password using Ansible. I get the error:
[jumphost] (item=manikins1) => {"ansible_loop_var": "item", "changed": false, "item": "manikins1", "msg": "unable to connect to database, check login_user and login_password are correct or /root/.my.cnf has the credentials. Exception message: 'cryptography' package is required for sha256_password or caching_sha2_password auth methods"}
- name: Sets the root password
mysql_user:
login_user=root
login_password="{{mysql_root_pass.stdout}}"
user=root
password="{{password}}"
check_implicit_admin=yes
host="{{item}}"
priv="*.*:ALL,GRANT"
with_items:
- "{{ ansible_hostname }}"
- 127.0.0.1
- ::1
- localhost
Solution
Although you did not give that information, the error message suggest you are using mysql 8 with sha256 or caching sha2 authentification.
Quoting notes on the official module documentation
Currently, there is only support for the mysql_native_password encrypted password hash module.
You have two options:
- Configure mysql 8 to use native passwords
- Don't use this module and modify the password by your own means (script, shell command)
Answered By - Zeitounator Answer Checked By - Terry (WPSolving Volunteer)