aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/roles/file_wait/tasks/check.yml
blob: 47122b7cdf56f36ab09cc21cb33cc3b2f8a31233 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
- name: Wait for connection
  ansible.builtin.wait_for_connection:
    timeout: '{{ file_wait_seconds }}'

- name: Check if file exists
  ansible.builtin.file:
    path: '{{ file_wait_path }}'
    state: file
  register: file_wait_check
  until: file_wait_check is succeeded
  retries: '{{ file_wait_seconds // file_wait_delay }}'
  delay: '{{ file_wait_delay }}'
  ignore_unreachable: true
  ignore_errors: true

- name: If host restarted, try again
  when: file_wait_check is unreachable
  block:
    - name: Show number of reboots
      ansible.builtin.debug:
        msg: 'Number of reboots left: {{ file_wait_reboots_left }}'

    - name: Decrement number of reboots
      ansible.builtin.set_fact:
        file_wait_reboots_left: '{{ (file_wait_reboots_left | int) - 1 }}'

    - name: Retry if there're more reboots
      ansible.builtin.include_tasks: check.yml
      when: (file_wait_reboots_left | int >= 0)