---
- name: OVN subnet | Get the ovn_host_annotation
  block:
    - name: OVN subnet | Fetch the ovn_host_subnet annotation
      win_shell: |
        $ErrorActionPreference = "Stop"
        $output = & "{{ install_path }}\kubectl.exe" get node {{ ansible_hostname | lower }} --output json
        if($LASTEXITCODE) {
            Throw "Failed to execute kubectl.exe get node"
        }
        $json = $output | ConvertFrom-Json
        $json.metadata.annotations.ovn_host_subnet
      register: cmd_output
      until: cmd_output.stdout != ""
      retries: 10
      delay: 3
  rescue:
    - fail:
        msg: Could not fetch OVN host subnet, check that kubelet can connect to kubernetes

- name: OVN subnet | Set ovn_subnet and ovn_gateway_ip facts
  set_fact:
    ovn_subnet: "{{ cmd_output.stdout | trim }}"

- name: OVN subnet | Set the ovn_gateway_ip
  set_fact:
    # Set the ovn_gateway_ip by parsing the ovn_subnet
    ovn_gateway_ip: "{{ ovn_subnet.split('/')[0][:-1] + '1' }}"

- debug: var=ovn_subnet
- debug: var=ovn_gateway_ip
