自学内容网 自学内容网

ansible使用shell模块的环境变量问题

在本机写了一个shell脚本,关于操作mysql的,在本机执行脚本可以正常操作数据库,脚本运行正常。
但是使用ansible

ansible -i ./hosts test_teledb -m copy -a "src=/etc/ansible/scripts/check.sh dest=/tmp"

ansible -i ./hosts test_teledb -m shell  -a "sh /tmp/check.sh"    

却报错
mysql :command not found

解决办法
通过在脚本中输出 whoami 查看ansible推送的脚步执行用户,如果用户是正确的,在脚本的头部位置添加

source ~/.bash_profile

原文地址:https://blog.csdn.net/DBA_ChenJR/article/details/137658073

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!