How to run multiple playbooks concurrently in parallel

47 views
Skip to first unread message

wpgpo...@gmail.com

unread,
Jun 7, 2024, 5:46:56 PMJun 7
to Ansible Project
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

Todd Lewis

unread,
Jun 7, 2024, 6:12:41 PMJun 7
to ansible...@googlegroups.com, uto...@gmail.com
Try this:
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 &
wait
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/f996beb8-5458-4194-817b-33ee6221713bn%40googlegroups.com.

-- 
Todd

wpgpo...@gmail.com

unread,
Jun 10, 2024, 4:06:03 PMJun 10
to Ansible Project
Thank you so much again Todd. It works and confirmed.
Reply all
Reply to author
Forward
0 new messages