簡體   English   中英

ansible 上的 shell 命令中的語法錯誤

[英]syntax error in shell command over ansible

團隊,

我的任務在下面,我只是想拉一個模式匹配最多 5 個字符的 pod,但在 ansible output 中出現錯誤。

- 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

output:

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

預期 output:

csi-vdiskplugin-asdf9d

命令在 linux 終端上完美運行

使用 shell 模塊

- 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM