我最近将我的流浪汉从ubuntu / trusty-64升级到了bento / ubuntu-16.04.随着MySQL更新到5.7.我已经对我的剧本进行了几次更新,但在设置root用户的密码时我一直遇到困难.
在过去(5.7之前),以下就足够了:
- name: MysqL | Set the root password.
MysqL_user:
name=root
host=localhost
password={{ MysqL_root_password }}
become: true
- name: MysqL | Delete anonymous MysqL server user for {{ server_hostname }}
MysqL_user:
name=""
host="{{ server_hostname }}"
state="absent"
login_user=root
login_password={{ MysqL_root_password }}
但是,现在我的剧本在这一步失败了,返回:
“Access denied for user ‘root’@’localhost'”
TASK [MysqL : MysqL | Delete anonymous MysqL server user for vagrant] **********
task path: /Users/jonrobinson/vagrant/survey/playbooks/roles/MysqL/tasks/MysqL.yml:51
fatal: [vagrant]: Failed! => {"changed": false, "Failed": true, "msg": "unable to connect to database, check login_user and login_password are correct or /home/vagrant/.my.cnf has the credentials. Exception message: (1698, \"Access denied for user 'root'@'localhost'\")"}
我尝试了几件事:
>为root用户设置密码空白MysqL_root_password =“”
>尝试删除root用户,然后使用Ansible重新创建它.我得到相同的错误可能是因为它试图在root用户处理.
>手动更新MysqL中的root密码. – 除非我删除root用户并使用所有权限重新创建root用户,否则这似乎也不起作用(密码无法识别).只是更新root用户密码似乎没有变化.
我的完整MysqL YAML:
---
- name: MysqL | install MysqL packages
apt: pkg={{ item }} state=installed
become: true
with_items:
- MysqL-client
- MysqL-common
- MysqL-server
- python-MysqLdb
- name: MysqL | create MysqL configuration file
template:
src=my.cnf.j2
dest=/etc/MysqL/my.cnf
backup=yes
owner=root
group=root
mode=0644
become: true
- name: MysqL | create MysqLD configuration file
template:
src=MysqLd.cnf.j2
dest=/etc/MysqL/conf.d/MysqLd.cnf
backup=yes
owner=root
group=root
mode=0644
become: true
- name: MysqL | restart MysqL
service: name=MysqL state=restarted
become: true
- name: MysqL | Set the root password.
MysqL_user:
name=root
host=localhost
password={{ MysqL_root_password }}
become: true
- name: MysqL | Config for easy access as root user
template: src=MysqL_root.my.cnf.j2 dest=/root/.my.cnf
become: true
- name: MysqL | Config for easy access as root user
template: src=MysqL_root.my.cnf.j2 dest={{ home_dir }}/.my.cnf
when: "'{{ user }}' != 'root'"
- name: MysqL | Delete anonymous MysqL server user for {{ server_hostname }}
MysqL_user: name="" host="{{ server_hostname }}" state="absent" login_user=root login_password={{ MysqL_root_password }}
- name: MysqL | Delete anonymous MysqL server user for localhost
MysqL_user: name="" state="absent" host=localhost login_user=root login_password={{ MysqL_root_password }}
- name: MysqL | Secure the MysqL root user for IPV6 localhost (::1)
MysqL_user: name="root" password="{{ MysqL_root_password }}" host="::1" login_user=root login_password={{ MysqL_root_password }}
- name: MysqL | Secure the MysqL root user for IPV4 localhost (127.0.0.1)
MysqL_user: name="root" password="{{ MysqL_root_password }}" host="127.0.0.1" login_user=root login_password={{ MysqL_root_password }}
- name: MysqL | Secure the MysqL root user for localhost domain (localhost)
MysqL_user: name="root" password="{{ MysqL_root_password }}" host="localhost" login_user=root login_password={{ MysqL_root_password }}
- name: MysqL | Secure the MysqL root user for {{ server_hostname }} domain
MysqL_user: name="root" password="{{ MysqL_root_password }}" host="{{ server_hostname }}" login_user=root login_password={{ MysqL_root_password }}
- name: MysqL | Remove the MysqL test database
MysqL_db: db=test state=absent login_user=root login_password={{ MysqL_root_password }}
- name: MysqL | create application database user
MysqL_user: name={{ dbuser }} password={{ dbpass }} priv=*.*:ALL host='%' state=present login_password={{ MysqL_root_password }} login_user=root
- name: MysqL | restart MysqL
service: name=MysqL state=restarted
become: true
最佳答案:
我弄清楚了.当没有提供密码时,问题的要点与使用auth_socket的root用户的MysqL 5.7有关.请参阅以下内容:“That plugin doesn’t care and doesn’t need a password. It just checks if the user is connecting using a UNIX socket and then compares the username.”
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('test');
而必须使用:
ALTER USER 'root'@'localhost' IDENTIFIED WITH MysqL_native_password='test';
解决方案1:但是,Ansible,从版本2.0.2开始没有考虑到这一点.我可以通过在安装MysqL之前设置密码来解决这个问题
- name: Specify MysqL root password before installing
debconf: name='MysqL-server' question='MysqL-server/root_password' value='{{MysqL_root_password | quote}}' vtype='password'
become: true
- name: Confirm MysqL root password before installing
debconf: name='MysqL-server' question='MysqL-server/root_password_again' value='{{MysqL_root_password | quote}}' vtype='password'
become: true
- name: MysqL | install MysqL packages
apt: pkg={{ item }} state=installed
become: true
with_items:
- MysqL-client
- MysqL-common
- MysqL-server
- python-MysqLdb
...
However, this has also since been addressed by Ansible
解决方案2:最简单的解决方案是将Ansible升级到2.2.1
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。