return code as the input value for another play

52 views
Skip to first unread message

danish09

unread,
Mar 21, 2021, 7:50:11 AM3/21/21
to Ansible Project
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.

---
- hosts: all

- import_playbook: sftp.yml

- import_playbook: reboot.yml


---
- hosts: sftp01

  tasks:
    - name: create file
      shell: touch /home/xxxxxxxxx/sftp_now

----
- hosts: remote

  tasks:

    - name: rebooting the remote test box
      reboot:
        test_command: whoami
      become: true

danish09

unread,
Mar 21, 2021, 7:50:38 AM3/21/21
to Ansible Project
Thanks

Ramakrishna Veeragandham

unread,
Mar 21, 2021, 8:30:37 AM3/21/21
to ansible...@googlegroups.com
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.



Thanks,
Ram

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/9bbdba5d-3271-4612-a8ed-631cf4ff7d75n%40googlegroups.com.

Brian Coca

unread,
Mar 22, 2021, 11:32:25 AM3/22/21
to Ansible Project
Look at AWX/Tower workflows.

https://docs.ansible.com/ansible-tower/latest/html/userguide/workflows.html

--
----------
Brian Coca

danish09

unread,
Mar 23, 2021, 7:54:19 AM3/23/21
to Ansible Project
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

Reply all
Reply to author
Forward
0 new messages