团队,
我的任务在下面,我只是想拉一个与模式匹配最多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终端上完美运行
答案 0 :(得分: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