Ansible/deployment: how to coordinate actions running in sequence on different servers?

1

Would anyone know how to create an Ansible playbook to run the following actions in the right order?

  1. Stop Tomcat on the application servers
  2. Update the database on the database server
  3. Update the webapps on the application servers
  4. Restart Tomcat on the application servers

I'm able to run these actions either in the right sequence or on the right servers. I'm struggling to order actions and get them to run on the right server in a single play. Any pointer to an answer would be much appreciated!

marcv81

Posted 2014-11-27T17:42:26.323

Reputation: 371

1Can you show what you have? Are you specifying different hosts for different tasks? Are you using pre_task/post_task? – Mxx – 2014-11-28T05:27:48.950

1I'd say that if you have these actions in sequence in a single playbook then they will always be run in the right order on each server; please enhance your question to show your config and what's going wrong. – wurtel – 2014-11-28T11:59:14.807

I didn't realise I could write several plays per playbook. Problem solved as far as I'm concerned. Apologies for the unclear question and thanks for the comments. – marcv81 – 2014-11-28T12:44:27.737

Answers

4

For others that want more detail on how to do this as you can run multiple plays against multiple sets of servers as per the below in a single playbook:

---
- hosts: applicationservers
  tasks:
    - name: code for shutting down tomcat on application servers

- hosts: databaseservers
  tasks:
    - name: code for updating the database servers

- hosts: applicationservers
  tasks:
    - name: code for updating the webapps on the application servers

    - name: code for restarting tomcat on the application servers

You can also use roles to do most of this, and I would recommend looking at using handlers for the restarting of tomcat.

PhillipHolmes

Posted 2014-11-27T17:42:26.323

Reputation: 219