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

    命令:

    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 >>
    [Errno 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

  • 相关阅读:
    第二阶段团队项目冲刺第三天
    第二阶段团队项目冲刺第二天
    第二阶段团队项目冲刺第一天
    第二次冲刺站立会议05
    第二次冲刺站立会议04
    第二次冲刺站立会议03
    第二次冲刺站立会议02
    第二次冲刺站立会议01
    第二次冲刺计划会议
    cnblogs.com的用户体验
  • 原文地址:https://www.cnblogs.com/losbyday/p/7375238.html
Copyright © 2011-2022 走看看