浪人 发表于 2018-1-3 13:26:46

ansible执行shell模块和command模块报错

  命令:
  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

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

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

  本机上面(192.168.20.33):

  在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
页: [1]
查看完整版本: ansible执行shell模块和command模块报错