How to run multiple playbooks concurrently in parallel

Hello Group,

Is there a way that I can run a playbook concurrently?

Currently, if I’m running the script with multiple playbook (2x or 3x or so), it will run and finish the first playbook before proceeding on the next playbook in the line.

The idea is that I want to run a script that has multiple playbooks (2x or 3x or so) concurrently in parallel at the same time. Meaning, the job1, job2, job3, and job4 will run at the same time and should NOT wait to finish each other.

Any help and guidance is highly appreciated.

An example of the scenarios are below.

Scenarios
shell script

/home/fuser/scripts/ansbile/playbooks/servers/server_job.sh

server_job.sh

ansible-playbook main_job.yml -e “server=job1” --limit runtime-host-group
ansible-playbook main_job.yml -e “server=job2” --limit runtime-host-group
ansible-playbook main_job.yml -e “server=job3” --limit runtime-host-group
ansible-playbook main_job.yml -e “server=job4” --limit runtime-host-group

runtime-host-group

[runtime-host-group]
runtime001
runtime002

main_job.yml (using import_playbook)

  • name: Playbook to Stop/Start
    hosts: all

  • name: Stop-Runtime | Stop the Runtime
    import_playbook: “/home/fuser/scripts/ansbile/playbooks/servers/playbook_sbxrun_runtime_stop_systemCTL.yml”

  • name: Start-Runtime | Start the Runtime
    import_playbook: “/home/fuser/scripts/ansbile/playbooks/servers/playbook_sbxrun_runtime_start_systemCTL.yml”

playbook_sbxrun_runtime_stop_systemCTL.yml

  • name: Process to STOP
    hosts: all

tasks:

  • name: SystemCTL | STOP
    service:
    name: “{{ item }}”
    state: stopped
    become: yes
    with_items:

  • runtime-{{server}}.service

  • monitor-{{server}}.service

playbook_sbxrun_runtime_start_systemCTL.yml

  • name: Process to START
    hosts: all

tasks:

  • name: SystemCTL | STOP
    service:
    name: “{{ item }}”
    state: started
    become: yes
    with_items:

  • runtime-{{server}}.service

  • monitor-{{server}}.service

Thank you…

Erwin

Try this:
server_job.sh

Thank you so much again Todd. It works and confirmed.