<p>I am trying to validate that the pod is deleted. </p>

<pre><code>- name: Verify whether the POD is deleted
  command: "{{ local_kubectl }} get pod {{ pod_name}}"
</code></pre>

<p>but the task is failing as the command displays error as below</p>

<blockquote>
  <p>'Error from server (NotFound): pods   ....'</p>
</blockquote>

<p>But this is expected when i am checking for deletion of pod. </p>

<p>How to pass this task when it returns an error message?</p>

Samselvaprabu
<p>You can just directly specify this using the <a href="https://docs.ansible.com/ansible/latest/modules/k8s_module.html#k8s-module" rel="nofollow noreferrer">k8s module</a></p>

<pre><code>- name: Delete the POD
  k8s:
    api_version: v1
    kind: Pod
    namespace: "{{ k8s_namespace }}"
    name: "{{ pod_name }}"
    state: absent
</code></pre>

<p>Another path is to <a href="https://docs.ansible.com/ansible/latest/user_guide/playbooks_error_handling.html#controlling-what-defines-failure" rel="nofollow noreferrer">redefine "failure"</a> to check for the expected result string.</p>

<pre><code>- name: Verify whether the POD is deleted
  command: "{{ local_kubectl }} get pod {{ pod_name}}"
  register: verify
  failed_when: "'NotFound' not in verify.stderr"
</code></pre>
