# Command Execution Return Code "rc"

**URL:** <https://forum.ansible.com/t/command-execution-return-code-rc/21051>\
**Category:** Ansible Project\
**Created:** [April 3, 2016, 3:33pm UTC](https://forum.ansible.com/t/command-execution-return-code-rc/21051 "2016-04-03T15:33:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Herbie\_van\_Dalsen](https://avatars.discourse-cdn.com/v4/letter/h/b5a626/32.png) [@Herbie\_van\_Dalsen](https://forum.ansible.com/u/Herbie_van_Dalsen)\
**Post date:** [April 3, 2016, 3:33pm UTC](https://forum.ansible.com/t/command-execution-return-code-rc/21051/1 "2016-04-03T15:33:36Z")

</div>

Hi there,

I cannot find a way to check successful execution of the previous command before doing the next… And I have come across the mention of rc, but how to test for that?

Thank you in advance

H.

---

<div class="post-metadata">

**Author:** ![imed\_khaskhoussi](https://avatars.discourse-cdn.com/v4/letter/i/919ad9/32.png) [@imed\_khaskhoussi](https://forum.ansible.com/u/imed_khaskhoussi)\
**Post date:** [April 4, 2016, 2:12pm UTC](https://forum.ansible.com/t/command-execution-return-code-rc/21051/2 "2016-04-04T14:12:21Z")

</div>

rc=0 for success

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [April 4, 2016, 2:31pm UTC](https://forum.ansible.com/t/command-execution-return-code-rc/21051/3 "2016-04-04T14:31:54Z")

</div>

Use register to capture the results returned by the module and then you can use an assert step to check that the results contain what you expect.

See  
[http://docs.ansible.com/ansible/playbooks\_variables.html#registered-variables](http://docs.ansible.com/ansible/playbooks_variables.html#registered-variables)

and

[http://docs.ansible.com/ansible/assert\_module.html](http://docs.ansible.com/ansible/assert_module.html)

There are lots of examples of using assert in the integration test roles here: [https://github.com/ansible/ansible/tree/devel/test/integration/roles](https://github.com/ansible/ansible/tree/devel/test/integration/roles)

HTH

Jon
