外壳程序命令在ansible中的语法错误

问题描述 投票:0回答:1

团队,

我的任务在下面,我只是试图将模式匹配的豆荚拉至最多5个字符,但在无用输出中出现错误。

- 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个回答
0
投票

二手外壳模块

- 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
© www.soinside.com 2019 - 2024. All rights reserved.