ansible 远程执行时提示 command not found 问题
问题
最近在学习 ansible ,在使用普通用户远程执行 ip a 命令是发现提示错误:/bin/sh: ip: command not found。
原因
command not found 命令未找到,一般想到的是环境变量的问题。网上查找资料,也证实了这个猜测,根本原因是 ansible 登录方式为 non-login shell(与之对应的是 login shell )。login shell 登陆后会加载 /etc/profile、~/.bash_profile,而 non-login shell 登陆后不会加载 /etc/profile、~/.bash_profile,而是加载 /etc/bashrc、~/.bashrc,一般的环境变量都设置在 /etc/profile、~/.bash_profile,所以这时就出现了找不到命令的情况。
- login shell:取得 shell 需要完整的登录流程,就是说通过输入账号和密码登录系统。
- non-login shell:取得 shell 不需要重复登录的举动。比如 X Window 登录 linux 后,再以 X 的图形界面启动终端机,此时那个终端机并没有需要输入账号和密码或者在原本的 shell 环境下再次执行 sh 命令,同样也没有输入账号密码就进入新的 shell环境(前一个 shell 的子进程)。
解决方案
- 把 /etc/profile、~/.bash_profile中的环境变量同步一份到 /etc/bashrc、~/.bashrc,这种方案不推荐。
- 执行命令或脚本时命令都写全路径,我一般采用这种方案。
- 执行命令和脚本时前面首先加载环境变量,比如:
. /etc/profile &> /dev/null; . ~/.bash_profile &> /dev/null; ip a;。
ansible 远程执行时提示 command not found 问题的更多相关文章
- Windows 2008 远程登陆时提示"要登录到此远程计算机,您必须被授予允许通过终端登录登录的权限"
ECS Win2008 远程时提示"要登录到此远程计算机,您必须被授予允许通过终端登录登录的权限"的解决方法 问题描述 ECS Windows 2008 远程登陆时提示&quo ...
- Ansible 远程执行命令
写法如下: [root@localhost ~]$ ansible 192.168.119.134 -m command -a 'date' # 对指定的主机远程执行命令,-m 指定使用哪个模块,-a ...
- Ansible 远程执行脚本
1. 先在服务端创建一个 shell 脚本 [root@localhost ~]$ cat /tmp/test.sh #!/bin/bash echo "hello world" ...
- 执行脚本 提示 command not found
问题现象: 初学shell,写了个脚本, 1.从windows 写好 脚本,然后部署到 linux 上. 2.chmod +x之后执行提示command not found,系统环境redhat9,用 ...
- 解决安装vc2005运行库时提示Command line option syntax error.Type Command/?for Help
安装vc2005运行库时提示 这是因为它要自解压到用户的临时文件夹下,如果用户名中带中文,就会报错. 简单的解决方法是,手动解压之,再安装 当然,你也可以修改用户名或者再新建个用户.
- 将window的shell脚本通过ftp传输到Linux服务器后, shell脚本中执行时提示“没有那个文件或目录”的解决办法
出现bad interpreter:No such file or directory的原因,是文件格式的问题.这个文件是在Windows下编写的.换行的方式与Unix不一样,但是在vim下面如果不S ...
- 使用sudo执行命令提示command not found
笔记: 使用源码部署nginx的时候,使用sudo nginx提示command not found,但是直接使用nginx会导致权限问题: 这种情况应该是环境变量导致的,使用 env |grep P ...
- 安装SQL Servre2000时提示“command line option syntax error! type command /? for help”
问题: 当程序正在安装ms数据访问组件时,弹出错误提示框:command line option syntax error,type command/? for help,点击确定继续:到了程序正在安 ...
- paramiko模拟ansible远程执行命令
主模块 #!/usr/bin/env python from multiprocessing import Process import paramiko import time import sys ...
随机推荐
- Linux后台执行脚本 &与nohup
Linux后台执行脚本的方式: 0.脚本代码 [root@VM_1_3_centos apps]# cat test.php <?php sleep(5); echo "hello w ...
- 查找android so文件中绕过c/c++ api直接调用SYSCALL的方法位置
很多应用会通过arm汇编,自行调用syscall,直接操作系统内核,来绕过c层的hook,保证程序安全 所以想hook的话只能找到这些方法的c入口分别hook 可以通过查找bxls指令找到这些位置
- nginx的安装和负载均衡例子(RHEL/CentOS7.4)
首先安装RHEL/CentOS7.4 mini ,然后关闭防火墙和 selinux ,更新系统(参看配置linux使用本地yum安装源和Redhat7/CentOS7 关闭防火墙和 selinux两个 ...
- Java +selenium Navigation接口介绍
Navigation接口主要实现对浏览器的前进.后退.打开网址.刷新当前页面等操作的. void back():就是操作当前页面后退,相当于网页的后退按钮. void forward():就是操作当前 ...
- [Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value. Prop being
[Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent c ...
- C#后台获取根路径
C#后台获取当前系统根路径: string absoluteurl = Context.Request.Url.AbsoluteUri.Replace(Context.Request.RawUrl, ...
- js中浅谈this对象(未补充完整)
什么是this? 1.javascript语言中,一切皆为对象(除了 undefined 和 null 之外),运行环境也是对象,所以函数都是在某个对象之中运行,this就是这个对象(环境). 2.t ...
- VLAN基础配置及Access接口 实验1
1.Access接口 是交换机上与PC机上相连的端口 2.当主机向交换机发送数据帧时,经过的Access口会将该帧加一个与自己PVID一致的VLAN标签 当交换机的Access口要发送给PC机一个带有 ...
- golang的数据类型之字符串类型
基本案例: [root@node3 shangxuetang]# cat string.go package main import "fmt" func main() { //s ...
- php分割url,获取参数query
#测试网址: http://localhost/blog/testurl.php?id=5 //获取域名或主机地址echo $_SERVER['HTTP_HOST']."<br> ...