首页 > 解决方案 > ansible无法识别yq处理器

问题描述

团队,在我的剧本中,我在 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

标签: ansibleansible-template

解决方案


我所做的是在我的剧本中添加了一个通过 pip 安装 yq 的任务:

- name: Install yq
  pip:
    name: ['yq']

推荐阅读