I am trying to validate that the pod is deleted.
- name: Verify whether the POD is deleted
command: "{{ local_kubectl }} get pod {{ pod_name}}"
but the task is failing as the command displays error as below
'Error from server (NotFound): pods ....'
But this is expected when i am checking for deletion of pod.
How to pass this task when it returns an error message?
You can just directly specify this using the k8s module
- name: Delete the POD
k8s:
api_version: v1
kind: Pod
namespace: "{{ k8s_namespace }}"
name: "{{ pod_name }}"
state: absent
Another path is to redefine "failure" to check for the expected result string.
- name: Verify whether the POD is deleted
command: "{{ local_kubectl }} get pod {{ pod_name}}"
register: verify
failed_when: "'NotFound' not in verify.stderr"
Try k8s_facts
- k8s_facts:
kind: Pod
name: "{{ pod_name}}"
register: result
- debug:
var: result
(not tested)