From f7a43f59813ad05e35ce52ffccb42b3448ce99a6 Mon Sep 17 00:00:00 2001 From: friedrich goerz Date: Tue, 3 May 2022 10:57:55 +0200 Subject: [PATCH] DEV-452: added workaround to fix problem with missing hetzner internal network --- .../tasks/_check_for_internal_address.yml | 37 +++++++++++++++++++ roles/hcloud/tasks/main.yml | 5 +++ roles/restore_maria/tasks/main.yml | 17 --------- 3 files changed, 42 insertions(+), 17 deletions(-) create mode 100644 roles/hcloud/tasks/_check_for_internal_address.yml diff --git a/roles/hcloud/tasks/_check_for_internal_address.yml b/roles/hcloud/tasks/_check_for_internal_address.yml new file mode 100644 index 0000000..cc60546 --- /dev/null +++ b/roles/hcloud/tasks/_check_for_internal_address.yml @@ -0,0 +1,37 @@ +--- +- name: "Block to handle missing internal hetzner server network" + block: + - name: "Increment the retry count" + set_fact: + retry_count: "{{ retry_count | default(0) | int + 1 }}" + + - name: "DEBUG" + debug: + msg: "current retry_count: {{ retry_count }}" + + - name: "DEBUG" + debug: + msg: "ansible_all_ipv4_addresses: {{ ansible_all_ipv4_addresses }}" + + - name: "DEBUG" + debug: + msg: "ansible_all_ipv4_addresses-FILTERED: {{ ansible_all_ipv4_addresses | ansible.netcommon.ipaddr(shared_service_network) }}" + + - name: "DEBUG - break if only one IPv4-address was found" + assert: + that: + - ansible_all_ipv4_addresses | length == 2 + rescue: + - name: "RESCUE - fail: Maximum retries reached" + fail: + msg: "max_retries of {{ max_retries }} reached. Plz check." + when: retry_count | int == max_retries | int + + - name: "RESCUE: wait_for {{ retry_delay }} sec. between retries" + wait_for: + timeout: "{{ retry_delay }}" + delegate_to: localhost + become: false + + - name: "Include _check_for_internal_address.yml one time again => increase retry_count" + include_tasks: _check_for_internal_address.yml diff --git a/roles/hcloud/tasks/main.yml b/roles/hcloud/tasks/main.yml index bd880d4..01a3262 100644 --- a/roles/hcloud/tasks/main.yml +++ b/roles/hcloud/tasks/main.yml @@ -9,6 +9,11 @@ name: hcloud tasks_from: _set_server_state +- name: "Checking if internal network up and runnig for <{{ inventory_hostname }}>" + include_role: + name: hcloud + tasks_from: _check_for_internal_address + - name: "Gathering current server infos from hetzner" hcloud_server_info: api_token: "{{ hetzner_authentication_ansible }}" diff --git a/roles/restore_maria/tasks/main.yml b/roles/restore_maria/tasks/main.yml index 518cf4d..51bc3dc 100644 --- a/roles/restore_maria/tasks/main.yml +++ b/roles/restore_maria/tasks/main.yml @@ -19,23 +19,6 @@ user={{ mysql_root_username }} password={{ mysql_root_password }} -- name: DEBUG - debug: - msg: "ansible_all_ipv4_addresses: {{ ansible_all_ipv4_addresses }}" - -- name: DEBUG - debug: - msg: "ansible_all_ipv4_addresses-FILTERED: {{ ansible_all_ipv4_addresses | ansible.netcommon.ipaddr(shared_service_network) }}" - -- name: DEBUG - debug: - msg: "ansible_all_ipv4_addresses-FILTERED-firstelem: {{ ansible_all_ipv4_addresses | ansible.netcommon.ipaddr(shared_service_network) | first }}" - -- name: DEBUG - break if only one IPv4-address was found - assert: - that: - - ansible_all_ipv4_addresses | length == 2 - - name: "Install mariadb via include_role" vars: mysql_packages: