0

Team,

my task is below and am just trying to pull a pod with a pattern match upto 5chars but am getting error in 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

expected output:

csi-vdiskplugin-asdf9d

command works perfectly on linux terminal

AhmFM
  • 1,552
  • 3
  • 23
  • 53

1 Answers1

0

used shell module

- 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
AhmFM
  • 1,552
  • 3
  • 23
  • 53