团队,在我的剧本中,我在 shell 模块中调用 yq,但它抱怨路径。 有人可以帮忙吗?我已经手动测试了 yq 和 jq 可用。
cat $HOME/.kube/config/cluster-user.kubeconfig | yq .contexts[0].name```
"site.test.com"
"site.test.com"
- name: "GET API server current-context name with YQ.. "
shell: "cat $HOME/.kube/config/cluster-user.kubeconfig | yq .["current-context"]"
register: string1
ignore_errors: true
- debug:
var: string1.stdout_lines
when: string1.stdout != ''
- name: "GET API server contexts name with YQ.. "
shell: "cat $HOME/.kube/config/cluster-user.kubeconfig | yq .contexts[0].name"
register: string2
ignore_errors: true
- debug:
var: string2.stdout_lines
when: string2.stdout != ''
- fail:
msg: "Validate if both string1 and string2 are same, if yes proceed..."
when: string2.stdout != string1.stdout
任何提示如何使 ansible 使用二进制文件?
输出:
TASK [GET API server contexts name with YQ..] ******************************************************************************************
fatal: [target1]: FAILED! => {"changed": true, "cmd": "cat $HOME/.kube/config/cluster-user.kubeconfig | yq .contexts[0].name", "delta": "0:00:00.006670", "end": "2019-09-30 18:15:13.829021", "msg": "non-zero return code", "rc": 127, "start": "2019-09-30 18:15:13.822351", "stderr": "/bin/sh: yq: command not found", "stderr_lines": ["/bin/sh: yq: command not found"], "stdout": "", "stdout_lines": []}
...ignoring
在剧本中的环境中添加了路径
环境: 路径:"{{ ansible_env。PATH }}:/usr/local/bin">
现在,我的二进制文件按预期使用。但是,我仍然在使用 yq 时遇到问题,因为它要求 jq。
我所做的是在我的剧本中添加了一个通过 pip 安装 yq 的任务:
- name: Install yq
pip:
name: ['yq']