-1

I am performing rolling updates in several cluster. Each cluster is a group in inventory.

I want to pause the playbook when a cluster is done (a group of hosts) and not after every host.

- hosts: 127.0.0.1
  connection: local
  gather_facts: no

  tasks:

  - name: prompt 1
    pause: 
      prompt: prompt1
    run_once: true

  - name: prompt 1
    pause:
      prompt: prompt2
    run_once: true

- hosts: "{{ target }}"
  gather_facts: no
  serial: 1
  become: yes
  become_method: sudo
  ignore_unreachable: true

  roles:
    - app

I would like to pause the playbook after one host group before the next host group begin.

For eg, If I have the group called eu_app, us_app, then after deploying all hosts in group eu_app, playbook has to wait for 15 minutes to deploy for next group us_app.

I tried using loop_control with group_names but it is pausing the playbook even for child groups present for the parent group. Pause should happen only for parent group.

U880D
  • 8,601
  • 6
  • 24
  • 40

1 Answers1

0

I want to pause the playbook when a cluster is done (a group of hosts) ... I would like to pause the playbook after one host group before the next host group begin.

According the documentation and example under Playbook execution, a minimal example with hosts like

[eu_app]
eu1.example.com
eu2.example.com
eu3.example.com

[us_app]
us1.example.com
us2.example.com
us3.example.com
ansible-inventory -i hosts --graph
@all:
  |--@eu_app:
  |  |--eu1.example.com
  |  |--eu2.example.com
  |  |--eu3.example.com
  |--@us_app:
  |  |--us1.example.com
  |  |--us2.example.com
  |  |--us3.example.com
  |--@ungrouped:

and playbook like

---
- hosts: eu_app
  become: false
  gather_facts: true

  tasks:

  - name: Show Facts
    debug:
      msg: "{{ item }}"
    when: item == inventory_hostname
    loop: "{{ ansible_play_hosts }}"

  - name: Make sure service has time to start or stop
    pause:
      seconds: 900 # 15 min
    when: not ansible_check_mode

- hosts: us_app
  become: false
  gather_facts: true

  tasks:

  - name: Show Facts
    debug:
      msg: "{{ item }}"
    when: item == inventory_hostname
    loop: "{{ ansible_play_hosts }}"

will result into the requested execution.

An other approach is shown under How to put pause between Ansible roles?

U880D
  • 8,601
  • 6
  • 24
  • 40