---

- name: "Checking present state for network <{{ current_network_name }}>"
  hcloud_network:
    api_token: "{{ hetzner_authentication_ansible }}"
    name: "{{ current_network_name }}"
    labels: "{{ current_network_labels }}"
    ip_range: "{{ shared_service_network }}"
    state: present
  register: hcloud_result
  delegate_to: 127.0.0.1
  become: false
  delay: 5
  retries: 30
  until: hcloud_result.hcloud_network is defined

- name: "Checking present state for subnetwork for <{{ current_network_name }}>"
  hcloud_subnetwork:
    api_token: "{{ hetzner_authentication_ansible }}"
    network: "{{ current_network_name }}"
    ip_range: "{{ shared_service_network }}"
    network_zone: eu-central
    type: cloud
    state: present
  register: hcloud_result
  delegate_to: 127.0.0.1
  become: false
  delay: 5
  retries: 30
  until: hcloud_result.hcloud_subnetwork is defined

- name: "Checking present state for server network <{{ current_network_name }}> on <{{ inventory_hostname }}>"
  hcloud_server_network:
    api_token: "{{ hetzner_authentication_ansible }}"
    network: "{{ current_network_name }}"
    server: "{{ inventory_hostname }}"
    state: present
  register: hcloud_result
  delegate_to: 127.0.0.1
  become: false
  delay: 5
  retries: 30
  until: hcloud_result.hcloud_server_network is defined
  tags:
    - update_networks
