From 83b50c10cd040445f2ee4cefa30bad6ca8eec6b9 Mon Sep 17 00:00:00 2001 From: Ruakij Date: Fri, 21 Oct 2022 08:42:37 +0200 Subject: [PATCH] Use new variables and fix requests --- netmaker_server/tasks/netmaker.yml | 48 +++++++++++++++++++++++------- netmaker_server/tasks/rqlite.yml | 36 ++++++++++++++-------- 2 files changed, 62 insertions(+), 22 deletions(-) diff --git a/netmaker_server/tasks/netmaker.yml b/netmaker_server/tasks/netmaker.yml index 961e0d1..fe4f3e4 100644 --- a/netmaker_server/tasks/netmaker.yml +++ b/netmaker_server/tasks/netmaker.yml @@ -4,26 +4,54 @@ failed_when: command.rc != 0 - name: Wait for netmaker-api to become available - ansible.builtin.wait_for: - host: "{{ inventory_hostname }}" - port: 8081 - state: started - when: "inventory_hostname == groups['netmaker'][0]" + uri: + url: 'https://{{ netmaker_api.host }}.{{ netmaker_base_domain }}:{{ netmaker_nginx.advertise_port }}' + return_content: yes + validate_certs: no + status_code: + - 404 + until: uri_output.status == 404 + retries: 24 # Retries for 24 * 5 seconds = 120 seconds = 2 minutes + delay: 5 # Every 5 seconds + register: uri_output + +# todo: check if exists? - name: Create default mesh-network 'server' uri: - url: 'http://netmaker-api.{{ netmaker.base_domain }}:8081/api/networks' + validate_certs: no + url: 'https://{{ netmaker_api.host }}.{{ netmaker_base_domain }}:{{ netmaker_nginx.advertise_port }}/api/networks' method: POST body: - netid: servers + netid: servnet addressrange: 10.92.0.0/24 addressrange6: fd92::/64 body_format: json headers: - Authorization: 'Bearer {{ netmaker.master_key }}' + Authorization: 'Bearer {{ netmaker_creds.master_key }}' + Content-Type: application/json + when: "inventory_hostname == groups['netmaker'][0]" + register: default_mesh + until: "default_mesh is not failed" + retries: 2 + delay: 10 + +# todo: check if exists? + +- name: Create token for default-network + uri: + validate_certs: no + url: 'https://{{ netmaker_api.host }}.{{ netmaker_base_domain }}:{{ netmaker_nginx.advertise_port }}/api/networks/servnet/keys' # todo: do implementation + method: POST + body: + name: "" + uses: 0 + body_format: json + headers: + Authorization: 'Bearer {{ netmaker_creds.master_key }}' Content-Type: application/json when: "inventory_hostname == groups['netmaker'][0]" - register: default_mesh_ok - until: "default_mesh_ok is not failed" + register: default_mesh_key + until: "default_mesh_key is not failed" retries: 2 delay: 10 diff --git a/netmaker_server/tasks/rqlite.yml b/netmaker_server/tasks/rqlite.yml index 182804a..956e787 100644 --- a/netmaker_server/tasks/rqlite.yml +++ b/netmaker_server/tasks/rqlite.yml @@ -9,12 +9,18 @@ failed_when: command.rc != 0 when: "inventory_hostname == groups['netmaker_server'][0]" -# - name: Waiting for rqlite to accept connections on 1st-node -# ansible.builtin.wait_for: -# host: "{{ inventory_hostname }}" -# port: 4001 -# state: started -# when: "inventory_hostname == groups['netmaker_server'][0]" +- name: Waiting for rqlite to accept connections on 1st-node + uri: + url: 'https://{{ netmaker_rqlite.http_host }}.{{ inventory_hostname }}:{{ netmaker_nginx.advertise_port }}/status' + return_content: yes + validate_certs: no + status_code: + - 401 + until: uri_output.status == 401 + retries: 24 # Retries for 24 * 5 seconds = 120 seconds = 2 minutes + delay: 5 # Every 5 seconds + register: uri_output + when: "inventory_hostname == groups['netmaker_server'][0]" - name: Start rqlite service for other nodes command: "docker-compose --project-directory /opt/netmaker_server/ up -d rqlite" @@ -22,9 +28,15 @@ failed_when: command.rc != 0 when: "inventory_hostname != groups['netmaker_server'][0]" -# - name: Waiting for rqlite to accept connections on other nodes -# ansible.builtin.wait_for: -# host: "{{ inventory_hostname }}" -# port: 4001 -# state: started -# when: "inventory_hostname != groups['netmaker_server'][0]" +- name: Waiting for rqlite to accept connections on other nodes + uri: + url: 'https://{{ netmaker_rqlite.http_host }}.{{ inventory_hostname }}:{{ netmaker_nginx.advertise_port }}/status' + return_content: yes + validate_certs: no + status_code: + - 401 + until: uri_output.status == 401 + retries: 24 # Retries for 24 * 5 seconds = 120 seconds = 2 minutes + delay: 5 # Every 5 seconds + register: uri_output + when: "inventory_hostname != groups['netmaker_server'][0]"