我可以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)
我不知道我做错了什么......
在~/.bash_aliaseswhile 中使用别名$HOME=/home/ubuntu作为:
alias k="kubectl -s http:xxxx"
Run Code Online (Sandbox Code Playgroud)
k这里代表不同服务器中的不同命令,我必须使用此功能,但我不能source在 Ansible shell 模块中使用它。
有没有其他方法可以解决它?
我读了几篇文章:
并尝试:
shell: ". /home/ubuntu/.bash_aliases && k get pods --all-namespaces | grep {{ serviceName }}"
Run Code Online (Sandbox Code Playgroud)
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)
shell: "source /home/ubuntu/.bash_aliases && …Run Code Online (Sandbox Code Playgroud) ansible ×2