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,以上谢谢各位!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论