# until failing with grep command

**URL:** <https://forum.ansible.com/t/until-failing-with-grep-command/23674>\
**Category:** Ansible Project\
**Tags:** kubernetes\
**Created:** [February 7, 2017, 6:41pm UTC](https://forum.ansible.com/t/until-failing-with-grep-command/23674 "2017-02-07T18:41:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vikram\_Ranabhatt](https://avatars.discourse-cdn.com/v4/letter/v/aca169/32.png) [@Vikram\_Ranabhatt](https://forum.ansible.com/u/Vikram_Ranabhatt)\
**Post date:** [February 7, 2017, 6:41pm UTC](https://forum.ansible.com/t/until-failing-with-grep-command/23674/1 "2017-02-07T18:41:50Z")

</div>

Here with the following piece of code is waiting for the kubernetest pod to be disappeared after launch.  
pod do disappeared but the script fails with the error.  
I want to wait till pod disappeared and the continue with rest of the task.

```auto
- name: Check ms pod has disappeared
  sudo: yes
  run_once: true
  when: ansible_hostname != "inception-{{ vms_subdomain }}"
  shell: "kubectl get pod --namespace=vms | grep {{ item.key }}"
  register: command_res
  with_dict: "{{ microservices }}"
  until: "command_res.rc == 1"
  retries: 10
  delay: 20

```

TASK [sp-sif : Check ms resouce has disappeared] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
Tuesday 07 February 2017 15:26:52 +0000 (0:00:02.051) 0:03:23.889 \*\*\*\*\*\*  
FAILED - RETRYING: TASK: sp-sif : Check ms resouce has disappeared (5 retries left).  
FAILED - RETRYING: TASK: sp-sif : Check ms resouce has disappeared (4 retries left).  
FAILED - RETRYING: TASK: sp-sif : Check ms resouce has disappeared (3 retries left).

failed: [kubernetes-master-vik202vmsservices-1] (item={‘key’: u’iwan’, ‘value’: {u’streams’: u’ncs-alarms’}}) =\> {“attempts”: 4, “changed”: true, “cmd”: “kubectl get pod --namespace=vms | grep iwanms”, “del  
ta”: “0:00:00.048855”, “end”: “2017-02-07 15:28:26.707882”, “failed”: true, “item”: {“key”: “iwan”, “value”: {“streams”: “ncs-alarmsf”}}, “rc”: 1, “start”: “2017-02-07 15:28:26.659027”, “stderr”: “”, "stdout  
": “”, “stdout\_lines”: , “warnings”: }

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [February 7, 2017, 7:41pm UTC](https://forum.ansible.com/t/until-failing-with-grep-command/23674/2 "2017-02-07T19:41:38Z")

</div>

In Ansible return code greater than 0 is a failure.

But you can change that with failed\_when:  
[https://docs.ansible.com/ansible/playbooks\_error\_handling.html#controlling-what-defines-failure](https://docs.ansible.com/ansible/playbooks_error_handling.html#controlling-what-defines-failure)

You kan use this to make it work:  
failed\_when: command\_res.rc \> 1
