Parallel deployment

Hello Ansible users!

I am looking for suggestions for my particular use case, for which I could not find many other solution online.

Let’s say my web application runs on 2 servers: 1 web-server + 1 db server.

To deploy each one of my servers, I have a playbook like one of the followings.

web_server.yml —

  • hosts: web_server

roles:

  • network

  • apache

  • firewall

db_server.yml —

  • hosts: db_server

roles:

  • network

  • mysql

  • firewall

Each “type” of server has a different set of roles, and I have just one server per type.

I am trying to write a main.yml that deploys web_server and db_server in parallel.

If I use “include” in main.yml, the playbooks are executed in a sequence. The only way I found to run everything in parallel is to use roles with whens, like

main.yml —

  • hosts: all

strategy: free

roles:

  • network

  • role: mysql

when: inventory_hostname in groups.db_server

  • role: apache

when: inventory_hostname in groups.web_server

  • firewall

The only cons of this approach is that with 10 different server types and 20 different roles, the playbook is not that readable.

Are there better ways to solve this use case?

Many thanks,

Marco