在~/.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 && k get pods --all-namespaces | grep {{ serviceName }}"
args:
executable: /bin/bash
Run Code Online (Sandbox Code Playgroud)
shell: "source /home/ubuntu/.bashrc && k get pods --all-namespaces | grep {{ serviceName }}"
args:
executable: /bin/bash
Run Code Online (Sandbox Code Playgroud)
以上两种尝试都给了我这个错误:
"/bin/bash: k: command not found"
Run Code Online (Sandbox Code Playgroud)
shell: "sudo -u ubuntu -i k get pods --all-namespaces | grep {{ serviceName }}"
Run Code Online (Sandbox Code Playgroud)
"-bash: k: command not found"
Run Code Online (Sandbox Code Playgroud)
shell: ssh -t localhost /bin/bash -ci 'k get pods --all-namespaces | grep {{ serviceName }}'
Run Code Online (Sandbox Code Playgroud)
"Pseudo-terminal will not be allocated because stdin is not a terminal.", "Host key verification failed."
Run Code Online (Sandbox Code Playgroud)
shell: ssh -tt localhost /bin/bash -ci 'k get pods --all-namespaces | grep {{ serviceName }}'
register: result
Run Code Online (Sandbox Code Playgroud)
"Host key verification failed."
Run Code Online (Sandbox Code Playgroud)
vars:
- kubeCommand: ""
tasks:
- name: Get Command Alias
shell: cat ~/.bash_aliases | awk -F[\"] '{print $2}'
register: result
- set_fact: kubeCommand={{ result.stdout }}
- name: Get service
shell: "{{ kubeCommand }} get pods --all-namespaces | grep {{ serviceName }}"
Run Code Online (Sandbox Code Playgroud)
但问题仍然存在。
任何帮助将不胜感激 :)
这有点难看,但是您可以alias k="kubectl -s http:xxxx"直接将您的内容放入.bashrc或source .bash_aliases来自.bashrc您的游戏,并且您必须编写:
shell: '/bin/bash -i -c "k get pods --all-namespaces | grep {{ serviceName }}"'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1319 次 |
| 最近记录: |