无法使用 Ansible 设置 MySQL root 密码

Not able to setup MySQL root password using Ansible

我无法使用 Ansible 设置 MySQL root 密码。我收到错误:

[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

虽然您没有提供该信息,但错误消息表明您正在使用 mysql 8 with sha256 或缓存 sha2 身份验证。

引用 notes on the official module documentation

Currently, there is only support for the mysql_native_password encrypted password hash module.

您有两个选择: