diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2023-08-10 17:50:50 +0200 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2023-08-10 19:30:13 +0200 |
commit | a86d828553d4d724d4ad3ca5335711b6bb1c0eb5 (patch) | |
tree | db7b9ae3803aec2f871c8ead356b9091a581c014 /roles/file_wait/tasks | |
parent | cloud_init_wait: tolerate reboots (diff) | |
download | infra-ansible-a86d828553d4d724d4ad3ca5335711b6bb1c0eb5.tar.gz infra-ansible-a86d828553d4d724d4ad3ca5335711b6bb1c0eb5.zip |
cloud_init_wait: factor out to file_wait
Diffstat (limited to 'roles/file_wait/tasks')
-rw-r--r-- | roles/file_wait/tasks/check.yml | 25 | ||||
-rw-r--r-- | roles/file_wait/tasks/main.yml | 7 |
2 files changed, 32 insertions, 0 deletions
diff --git a/roles/file_wait/tasks/check.yml b/roles/file_wait/tasks/check.yml new file mode 100644 index 0000000..1a7c138 --- /dev/null +++ b/roles/file_wait/tasks/check.yml @@ -0,0 +1,25 @@ +- name: Wait for connection + ansible.builtin.wait_for_connection: + timeout: '{{ file_wait_seconds }}' + +- name: Check if the 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 the host restarted, try again + block: + - name: Note a reboot happened + ansible.builtin.set_fact: + file_wait_reboots: '{{ (file_wait_reboots | int) - 1 }}' + + - name: Retry if there're more attempts + ansible.builtin.include_tasks: check.yml + when: (file_wait_reboots | int > 0) + when: file_wait_check is unreachable diff --git a/roles/file_wait/tasks/main.yml b/roles/file_wait/tasks/main.yml new file mode 100644 index 0000000..76dce68 --- /dev/null +++ b/roles/file_wait/tasks/main.yml @@ -0,0 +1,7 @@ +- name: Checking if the file exists + ansible.builtin.include_tasks: check.yml + +- name: Fail unless the file exists + ansible.builtin.fail: + msg: 'File is missing: {{ file_wait_path }}' + when: file_wait_check is not defined or file_wait_check is not succeeded or file_wait_check is unreachable |