1
votes

I have a use case where there is a dependency of playbooks. I have one set of hosts to start application on all my machines and then another set of hosts which are actual machines.

Now my question is, is it possible for ansible to run the second playbook( lets say to update a package) only when the first playbook is successfully executed and application started. The problem I am having here is that, the second playbook runs though the first one is not successful and application didn't start

Here I start application from a remote machine that has permission to all my machines and update package needs to be done on each machine. Hence they are two different playbooks which rely on each other.

First playbook
  hosts: A
  tasks: 
    - name: check if app started and ready
      command: x

Second Playbook
  hosts: B
  tasks:
    - name: run y command from B machine to execute on A
      command: y

Here the problem is second playbook doesn't care if command X is executed or not. As soon as first playbook is done( no matter success or fail, second one starts since they belong to different machines)

1
Is there any chance that you can share the playbooks and how you run them to give us a place to start to debug / work from? - Geoff
@Geoff I have updated the question. Do you have any possible solution for this ? - CR7
Nothing better than Bruce below. - Geoff

1 Answers

1
votes

If the plays are directly dependent on each other as seems to be the case, then I would not separate them into different playbooks, but rather into roles used in the same playbook. You would need to register a variable somewhere in the tasks of the first role, so that it can be used in the second play:

- hosts: first-set
  roles:
    - { role: update-app } # registers update_was_good

- hosts: second-set
  roles:
  - update-packages
    when: update_was_good