我在安装MysqL时遇到问题,
这是我的MysqL部分
--- - name: Install MysqL apt: name: "{{ item }}" with_items: - python-MysqLdb - MysqL-server - name: copy .my.cnf file with root password credentials template: src: templates/root/.my.cnf dest: ~/.my.cnf owner: root mode: 0600 - name: Start the MysqL service service: name: MysqL state: started enabled: true # 'localhost' needs to be the last item for idempotency,see # http://ansible.cc/docs/modules.html#MysqL-user - name: update MysqL root password for all root accounts MysqL_user: name: root host: "{{ item }}" password: "{{ MysqL_root_password }}" priv: "*.*:ALL,GRANT" with_items: - "{{ ansible_hostname }}" - 127.0.0.1 - ::1 - localhost
我有这个错误
Failed: [default] => (item=vagrant-ubuntu-trusty-64) => {"Failed": true,"item": "vagrant-ubuntu-trusty-64"} msg: unable to connect to database,check login_user and login_password are correct or ~/.my.cnf has the credentials Failed: [default] => (item=127.0.0.1) => {"Failed": true,"item": "127.0.0.1"} msg: unable to connect to database,check login_user and login_password are correct or ~/.my.cnf has the credentials Failed: [default] => (item=::1) => {"Failed": true,"item": "::1"} msg: unable to connect to database,check login_user and login_password are correct or ~/.my.cnf has the credentials Failed: [default] => (item=localhost) => {"Failed": true,"item": "localhost"} msg: unable to connect to database,check login_user and login_password are correct or ~/.my.cnf has the credentials
我的.my.cnf是
[client] user=root password={{ MysqL_root_password }}
并在服务器上复制时
[client] user=root password=root
我不明白为什么,〜/ .my.cnf被创建
项目Github
谢谢
当MysqL-server无头安装时,没有密码。所以要使.my.cnf工作,它应该有一个空白的密码行。这是我测试一个.my.cnf:
原文链接:https://www.f2er.com/ubuntu/349487.html[client] user=root password=
将.my.cnf放在您的流氓用户目录中,由root拥有,只能以root用户身份读取也很奇怪。
确认密码在.my.cnf中是空白的后,我能够在四个上下文中正确设置root密码。请注意,它之后无法运行,因为.my.cnf需要更新,所以它的幂等性测试失败。
有一个关于可执行的MysqL_user模块页面的注释,建议写入密码,然后写入.my.cnf文件。如果你这样做,你需要一个where子句到MysqL_user动作(可能在之前有一个文件stat)。
更优雅的是使用check_implicit_admin以及login_user和login_password。这是美丽的幂
作为第三种方式,也许check_implicit_admin使它更容易。
这是我的成功的手册显示上述,测试与几个新鲜的服务器。金达为此感到自豪。注意.my.cnf对于所有这些都是不必要的。
--- - hosts: MysqL vars: MysqL_root_password: fart tasks: - name: Install MysqL apt: name={{ item }} update_cache=yes cache_valid_time=3600 state=present sudo: yes with_items: - python-MysqLdb - MysqL-server #- name: copy cnf # copy: src=.my.cnf dest=~/.my.cnf owner=ubuntu mode=0644 # sudo: yes - name: Start the MysqL service sudo: yes service: name: MysqL state: started enabled: true - name: update MysqL root password for all root accounts sudo: yes MysqL_user: name: root host: "{{ item }}" password: "{{ MysqL_root_password }}" login_user: root login_password: "{{ MysqL_root_password }}" check_implicit_admin: yes priv: "*.*:ALL,GRANT" with_items: - "{{ ansible_hostname }}" - 127.0.0.1 - ::1 - localhost
(编辑删除my.cnf)