diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2023-08-10 11:52:16 +0200 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2023-08-10 11:58:03 +0200 |
commit | c2798850de5c73680837727246c1390558be0707 (patch) | |
tree | dbfa397a0d22f640f2d2a877a6212b0d599a063e | |
parent | cloud_init_wait: wait for SSH connection first (diff) | |
download | infra-ansible-c2798850de5c73680837727246c1390558be0707.tar.gz infra-ansible-c2798850de5c73680837727246c1390558be0707.zip |
cloud_init_wait: tolerate reboots
This insanity comes from RedHat themselves:
https://www.ansible.com/blog/tolerable-ansible
-rw-r--r-- | roles/cloud_init_wait/tasks/check.yml | 23 | ||||
-rw-r--r-- | roles/cloud_init_wait/tasks/main.yml | 23 |
2 files changed, 27 insertions, 19 deletions
diff --git a/roles/cloud_init_wait/tasks/check.yml b/roles/cloud_init_wait/tasks/check.yml new file mode 100644 index 0000000..2dc20aa --- /dev/null +++ b/roles/cloud_init_wait/tasks/check.yml @@ -0,0 +1,23 @@ +# Make a playbook usable immediately after creating a VM - even before +# the SSH server is started. +- name: Wait for SSH connection + ansible.builtin.wait_for_connection: + timeout: '{{ cloud_init_wait_seconds }}' + +# Again, make a playbook usable immediately after creating a VM - that includes +# waiting until cloud-init is done. +- name: Wait until cloud-init is finished + ansible.builtin.file: + path: '{{ cloud_init_wait_path }}' + state: file + register: boot_finished + until: boot_finished is succeeded + # About 5 minutes worth of attempts. + retries: '{{ cloud_init_wait_seconds // cloud_init_wait_delay }}' + delay: '{{ cloud_init_wait_delay }}' + ignore_unreachable: true + ignore_errors: true + +- ansible.builtin.include_tasks: check.yml + when: + - boot_finished is unreachable diff --git a/roles/cloud_init_wait/tasks/main.yml b/roles/cloud_init_wait/tasks/main.yml index c7ed595..dec4162 100644 --- a/roles/cloud_init_wait/tasks/main.yml +++ b/roles/cloud_init_wait/tasks/main.yml @@ -1,20 +1,5 @@ -# Make a playbook usable immediately after creating a VM - even before -# the SSH server is started. -- name: Wait for SSH connection - ansible.builtin.wait_for_connection: - timeout: '{{ cloud_init_wait_seconds }}' +- ansible.builtin.include_tasks: check.yml -# Again, make a playbook usable immediately after creating a VM - that includes -# waiting until cloud-init is done. -- name: Wait until cloud-init is finished - ansible.builtin.stat: - path: '{{ cloud_init_wait_path }}' - # WTF? Is this the best way to _just_ check if a file exists? - get_attributes: false - get_checksum: false - get_mime: false - register: boot_finished - until: boot_finished.stat.exists is not false - # About 5 minutes worth of attempts. - retries: '{{ cloud_init_wait_seconds // cloud_init_wait_delay }}' - delay: '{{ cloud_init_wait_delay }}' +- ansible.builtin.fail: + msg: Failed to wait until cloud-init is done + when: boot_finished is not defined or boot_finished is not succeeded |