From bbb3e03651a350e60ba7b4f4136335d21a2de0e9 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sat, 8 Oct 2022 23:40:59 +0200 Subject: [PATCH] get content from api scaleway --- playbook.yml | 3 +-- scaleway-k8s/tasks/k8s.yml | 16 ++++++++++++++ scaleway-k8s/tasks/main.yml | 37 ++++++-------------------------- scaleway-k8s/tasks/terraform.yml | 32 +++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 33 deletions(-) create mode 100644 scaleway-k8s/tasks/k8s.yml create mode 100644 scaleway-k8s/tasks/terraform.yml diff --git a/playbook.yml b/playbook.yml index ceaafda..503b9de 100644 --- a/playbook.yml +++ b/playbook.yml @@ -7,5 +7,4 @@ - hosts: local remote_user: valentin roles: - - scaleway-k8s - tags: ["create-cluster"] \ No newline at end of file + - scaleway-k8s \ No newline at end of file diff --git a/scaleway-k8s/tasks/k8s.yml b/scaleway-k8s/tasks/k8s.yml new file mode 100644 index 0000000..fc13648 --- /dev/null +++ b/scaleway-k8s/tasks/k8s.yml @@ -0,0 +1,16 @@ +- name: Get id of cluster + ansible.builtin.uri: + url: https://api.scaleway.com/k8s/v1/regions/fr-par/clusters + status_code: 200 + return_content: yes + method: GET + headers: + X-Auth-Token: "{{ scw_secret_key }}" + register: output + +- name: Display content GET scaleway + debug: + msg: "{{ item }}" + with_items: "{{ output.content |to_json }}" + +# | from_json | community.general.json_query('clusters[*]') \ No newline at end of file diff --git a/scaleway-k8s/tasks/main.yml b/scaleway-k8s/tasks/main.yml index c429ca0..8edb170 100644 --- a/scaleway-k8s/tasks/main.yml +++ b/scaleway-k8s/tasks/main.yml @@ -1,32 +1,7 @@ ---- -# tasks file for scaleway-k8s - -- name: Create directory {{ project_terraform }} - file: - path: "{{ project_terraform }}" - state: directory - -- name: Copy main.tf - template: - src: main.tf.j2 - dest: "{{ project_terraform }}/main.tf" - - -- name: display plan terraform - debug: - var: output - -- name: Create cluster scaleway - community.general.terraform: - project_path: '{{ project_terraform }}' - state: present - force_init: yes - environment: - SCW_ACCESS_KEY: "{{ scw_access_key }}" - SCW_SECRET_KEY: "{{ scw_secret_key }}" - register: output - -- name: display terraform result - debug: - var: output +- name: Create cluster k8s scaleway via terraform + ansible.builtin.import_tasks: terraform.yml + tags: ["create-cluster"] +- name: Get id Cluster + ansible.builtin.import_tasks: k8s.yml + tags: ["create-cluster", "api"] \ No newline at end of file diff --git a/scaleway-k8s/tasks/terraform.yml b/scaleway-k8s/tasks/terraform.yml new file mode 100644 index 0000000..f584d14 --- /dev/null +++ b/scaleway-k8s/tasks/terraform.yml @@ -0,0 +1,32 @@ +--- +# tasks file for create cluster k8s via terraform + +- name: Create directory {{ project_terraform }} + file: + path: "{{ project_terraform }}" + state: directory + +- name: Copy main.tf + template: + src: main.tf.j2 + dest: "{{ project_terraform }}/main.tf" + + +- name: display plan terraform + debug: + var: output + +- name: Create cluster scaleway + community.general.terraform: + project_path: '{{ project_terraform }}' + state: present + force_init: yes + environment: + SCW_ACCESS_KEY: "{{ scw_access_key }}" + SCW_SECRET_KEY: "{{ scw_secret_key }}" + register: output + +- name: display terraform result + debug: + var: output +