命令:

ansible -i hosts_20 st  -m shell -a 'service zabbix_agentd star'  -K --become

ansible -i hosts_20 st  -m shell -a 'lsof -i:10050'  -K --become

 

在shell模块报错:| FAILED | rc=127 >>
/bin/sh: lsof: command not found

ansible执行shell模块和command模块报错| FAILED | rc=127 >> /bin/sh: lsof: command not found和| rc=2 >> [Errno 2] No such file or directory

 

在command模块报错:| rc=2 >>
[Errno 2] No such file or directory

ansible执行shell模块和command模块报错| FAILED | rc=127 >> /bin/sh: lsof: command not found和| rc=2 >> [Errno 2] No such file or directory

 

 google了一下发现ansible使用shell或者command模块加载环境变量变了,

ansible加载的环境变量:

ansible执行shell模块和command模块报错| FAILED | rc=127 >> /bin/sh: lsof: command not found和| rc=2 >> [Errno 2] No such file or directory

本机上面(192.168.20.33):

ansible执行shell模块和command模块报错| FAILED | rc=127 >> /bin/sh: lsof: command not found和| rc=2 >> [Errno 2] No such file or directory

 

 

在ansible执行和在本机执行echo $pATH命令结果不一样..........................

ansible的command模块或者shell模块因为没有完全加载环境变量。

 

一个临时的解决方法就是在ansible使用shell或者command的模块的时候,强行改变当前系统环境变量:PAHT="/usr/local/sbin:/usr/sbin:/sbin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin";source /etc/profile;

从ansible -i hosts_20 st  -m shell -a 'lsof -i:10050'  -K --become

变成了ansible -i hosts_20 st  -m shell -a 'PAHT="/usr/local/sbin:/usr/sbin:/sbin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin";source /etc/profile;lsof -i:10050'  -K --become

相关文章:

  • 2021-12-07
  • 2021-07-04
  • 2022-12-23
  • 2021-07-31
  • 2022-12-23
  • 2021-05-15
  • 2022-01-02
  • 2021-05-28
猜你喜欢
  • 2022-12-23
  • 2021-03-29
  • 2022-12-23
  • 2021-09-13
  • 2021-11-07
  • 2021-09-16
  • 2021-11-20
相关资源
相似解决方案