【发布时间】: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