相关疑难解决方法(0)

无法使用Ansible来源.bashrc

我可以ssh到远程主机并做source /home/username/.bashrc- 一切正常.但是,如果我这样做:

- name: source bashrc
  sudo: no
  action: command source /home/username/.bashrc
Run Code Online (Sandbox Code Playgroud)

我明白了:

failed: [hostname] => {"cmd": ["source", "/home/username/.bashrc"], "failed": true, "rc": 2}
msg: [Errno 2] No such file or directory
Run Code Online (Sandbox Code Playgroud)

我不知道我做错了什么......

ansible

73
推荐指数
6
解决办法
5万
查看次数

无法在 Ansible 中获取 ~/.bash_aliases

~/.bash_aliaseswhile 中使用别名$HOME=/home/ubuntu作为:

alias k="kubectl -s http:xxxx"
Run Code Online (Sandbox Code Playgroud)

k这里代表不同服务器中的不同命令,我必须使用此功能,但我不能source在 Ansible shell 模块中使用它。

有没有其他方法可以解决它?

我读了几篇文章:

并尝试:

没有 - 1

  shell: ". /home/ubuntu/.bash_aliases && k get pods --all-namespaces | grep {{ serviceName }}"
Run Code Online (Sandbox Code Playgroud)

没有 - 2

  shell: ". /home/ubuntu/.bashrc && k get pods --all-namespaces | grep {{ serviceName }}"
Run Code Online (Sandbox Code Playgroud)

结果

以上两种尝试都给了我这个错误:

"/bin/sh: 1: k: not found"
Run Code Online (Sandbox Code Playgroud)

没有 - 3

  shell: "source /home/ubuntu/.bash_aliases && …
Run Code Online (Sandbox Code Playgroud)

ansible

3
推荐指数
1
解决办法
1319
查看次数

标签 统计

ansible ×2