Running commands depending on command result in other host

Problem:
We need to migrate an application from old CentOS 7 to REL 9. We do not intend to do an in-place upgrade. What we plan to do is the following:

  1. Do a backup of the application on the old node.
  2. Transport the backup to the new node.
  3. Restore the backup on the new node.
  4. If Step 3 is successful, stop the application on the old node and remove the IP from interface.
  5. If step 4 is successful, change the IP on the new node to the one from the old node and start the application.
  6. If step 5 is successful give the old machine the initial IP of the new machine.

Expected outcome:
I am looking for a way to run command on Node B depending on the result if commands on Node A

Foreman and Proxy versions:
3.9.3

I much appreciate any help.

Many thanks

Mike

In theory you should be able to do this with ansible.

I am new to Ansibel, it would help me if one could guide me to the right direction.

Thank you

Mike