【问题标题】:syntax error in shell command over ansible通过ansible的shell命令中的语法错误
【发布时间】:2023-03-14 06:53:01
【问题描述】:

团队,

我的任务在下面,我只是想拉一个模式匹配最多 5 个字符的 pod,但在 ansible 输出中出现错误。

- name: "fetch csi pod on node"
  #command: "kubectl get pods -n csi-vdiskplugin  --no-headers --field-selector spec.nodeName={{ inventory_hostname }} | grep -E csi-vdiskplugin-'[[:alnum:]]{5}' -o -w"
  command: kubectl get pods -n csi-vdiskplugin  --no-headers --field-selector spec.nodeName={{ inventory_hostname }} | grep -E csi-vdiskplugin-'[[:alnum:]]{5}' -o -w
  #command: "kubectl get pods -n csi-vdiskplugin  --no-headers --field-selector spec.nodeName={{ inventory_hostname }} --kubeconfig $KUBECONFIG" 
  #command: "kubectl get pods -n csi-vdiskplugin  --no-headers --field-selector spec.nodeName={{ inventory_hostname }}" 
  register: csi_pod
  delegate_to: localhost
  become: false

输出:

fatal: [node1 -> localhost]: FAILED! => {"changed": true, "cmd": ["kubectl", "get", "pods", "-n", "csi-vdiskplugin", "--no-headers", "--field-selector", "spec.nodeName=node1", "|", "grep", "-E", "csi-vdiskplugin-[[:alnum:]]{5}", "-o", "-w"], "delta": "0:00:00.574302", "end": "2020-04-30 07:00:28.104617", "msg": "non-zero return code", "rc": 1, "start": "2020-04-30 07:00:27.530315", "stderr": "Error: unknown shorthand flag: 'E' in -E\n\n\nExamples:\n  # List all pods in ps output format.\n  kubectl get pods\n  \n  # List all pods in ps output format with more information (such as node name).\n  kubectl get pods -o wide\n  \n  # List a single replication controller with spec

预期输出:

csi-vdiskplugin-asdf9d

命令在 linux 终端上完美运行

【问题讨论】:

    标签: shell ansible ansible-2.x ansible-inventory ansible-facts


    【解决方案1】:

    使用的外壳模块

    - name: "fetch csi pod on node"
      shell: "kubectl get pods -n csi-vdiskplugin  --no-headers --field-selector spec.nodeName={{ inventory_hostname }} | grep -E csi-vdiskplugin-'[[:alnum:]]{5}' -o -w"
      register: csi_pod
      delegate_to: localhost
      become: false
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-19
      • 2020-03-29
      • 2019-08-19
      • 1970-01-01
      • 1970-01-01
      • 2014-02-18
      • 2014-06-25
      相关资源
      最近更新 更多