ansible使用shell模块,设置mysql的密码,但是总是提示失败

1,ansible使用shell模块,设置mysql的密码,但是总是提示失败

2,代码如下:

- name: Create mysql user
  user:
    name: mysql
    create_home: no
    shell: /sbin/nologin


- name: Download mysql
  get_url:
    url: http://mirrors.163.com/mysql/Downloads/MySQL-5.5/mysql-{{mysql_version}}-linux-glibc2.12-x86_64.tar.gz
    dest: /usr/local/src


- name: Unzip mysql
  unarchive:
    src: /usr/local/src/mysql-{{mysql_version}}-linux-glibc2.12-x86_64.tar.gz
    dest: /usr/local/src/
    copy: no

- name: Rename mysql
  shell:
    mv /usr/local/src/mysql-{{mysql_version}}-linux-glibc2.12-x86_64 /usr/local/mysql && chown -R mysql:mysql {{basedir}}


- name: Create data storage
  file:
    path: /data/mysql
    state: directory
    owner: mysql
    group: mysql


- name: Init mysql
  shell:
    ./scripts/mysql_install_db --user=mysql --basedir={{basedir}} --datadir={{datadir}}
  args:
    chdir: "{{basedir}}"

- name: Create mysql script for centos6
  shell:
    cp "{{basedir}}/support-files/mysql.server"  /etc/init.d/mysqld && chmod 755 /etc/init.d/mysqld
  when: (ansible_distribution == "CentOS" and ansible_distribution_major_version == "6")

- name: Create mysql script for centos7
  copy:
    src: mysqld.service
    dest: /usr/lib/systemd/system/mysqld.service
  when: (ansible_distribution == "CentOS" and ansible_distribution_major_version == "7")
  notify:
    - Reload service

- name: Copy mysql config
  template:
    src: my.cnf.j2
    dest: /etc/my.cnf

- name: Restart mysqld
  service:
    name: mysqld
    state: restarted


- name: Set mysql root password
  shell:
    /usr/local/mysql/bin/mysqladmin -uroot password linlin

3,报错信息入下
图片描述

4,在mysql服务器本地执行 /usr/local/mysql/bin/mysqladmin -uroot password linlin 该命令没有任何问题。

5,以上谢谢各位!

阅读 596
评论
    撰写回答

    登录后参与交流、获取后续更新提醒