# return code as the input value for another play

**URL:** <https://forum.ansible.com/t/return-code-as-the-input-value-for-another-play/34821>\
**Category:** Ansible Project\
**Created:** [March 21, 2021, 11:50am UTC](https://forum.ansible.com/t/return-code-as-the-input-value-for-another-play/34821 "2021-03-21T11:50:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![danish09](https://avatars.discourse-cdn.com/v4/letter/d/919ad9/32.png) [@danish09](https://forum.ansible.com/u/danish09)\
**Post date:** [March 21, 2021, 11:50am UTC](https://forum.ansible.com/t/return-code-as-the-input-value-for-another-play/34821/1 "2021-03-21T11:50:11Z")

</div>

Hi,

My goal is to implement 2 separate playbooks from the root main.yml, however, I would like to execute the 2nd playbook only when the 1st gives a return code of 0.

---

<div class="post-metadata">

**Author:** ![danish09](https://avatars.discourse-cdn.com/v4/letter/d/919ad9/32.png) [@danish09](https://forum.ansible.com/u/danish09)\
**Post date:** [March 21, 2021, 11:50am UTC](https://forum.ansible.com/t/return-code-as-the-input-value-for-another-play/34821/2 "2021-03-21T11:50:37Z")

</div>

Thanks

---

<div class="post-metadata">

**Author:** ![Ramakrishna\_V](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@Ramakrishna\_V](https://forum.ansible.com/u/Ramakrishna_V)\
**Post date:** [March 21, 2021, 12:30pm UTC](https://forum.ansible.com/t/return-code-as-the-input-value-for-another-play/34821/3 "2021-03-21T12:30:14Z")

</div>

Registered variables can’t persists across different plays when the second playbook runs on another host than first playbook. Look at this below solution.

Solution: Store the required variable in a dummy host and refer that variable in another play through dummy host.

Example is given below.

[https://serverfault.com/questions/962040/sharing-ansible-variable-between-plays](https://serverfault.com/questions/962040/sharing-ansible-variable-between-plays)

Thanks,  
Ram

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [March 22, 2021, 3:31pm UTC](https://forum.ansible.com/t/return-code-as-the-input-value-for-another-play/34821/4 "2021-03-22T15:31:50Z")

</div>

Look at AWX/Tower workflows.

[https://docs.ansible.com/ansible-tower/latest/html/userguide/workflows.html](https://docs.ansible.com/ansible-tower/latest/html/userguide/workflows.html)

---

<div class="post-metadata">

**Author:** ![danish09](https://avatars.discourse-cdn.com/v4/letter/d/919ad9/32.png) [@danish09](https://forum.ansible.com/u/danish09)\
**Post date:** [March 23, 2021, 11:54am UTC](https://forum.ansible.com/t/return-code-as-the-input-value-for-another-play/34821/5 "2021-03-23T11:54:19Z")

</div>

Thanks both.

Using Tower, unfortunately, is not something that I can jump over to. Though, i might just give it a read. For now, I have just gone back to calling 2 separate playbooks individually.

Thanks
