-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.yml
98 lines (82 loc) · 2.96 KB
/
test.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
- hosts: localhost
vars_files:
- .local.vars.yml
vars:
civo_cluster_name: kameshs-gloo-demos
civo_api_url: 'https://api.civo.com/v2/kubernetes/clusters'
civo_k3s_cluster_name: kameshs-gloo-demos
civo_k3s_cluster_size: g3.k3s.xlarge
civo_k3s_cluster_nodes: 1
civo_network_label: 'Default'
# LON1, FRA1, NYC1
civo_region: LON1
civo_kubernetes_version: 1.21.2+k3s1
civo_firewall_rules: 6443,80,443,8080,8443,9900,15443,15021,15012,15017
clusters_list_query: "items[?name=='{{ civo_cluster_name }}']"
network_query: "json[?label=='{{ civo_network_label }}']"
tasks:
- name: "Get Networks"
ansible.builtin.uri:
url: "https://api.civo.com/v2/networks/?region={{ civo_region }}&label=Default"
body_format: json
return_content: yes
headers:
Authorization: "bearer {{ civo_api_key }}"
register: civo_networks
# - debug:
# var: civo_networks
- name: "Set Network facts"
set_fact:
network_id: "{{ civo_networks | community.general.json_query(network_query) | first | community.general.json_query('id') }}"
- name: "Get Clusters"
ansible.builtin.uri:
url: "{{ civo_api_url }}/?region={{ civo_region }}"
body_format: json
return_content: yes
headers:
Authorization: "bearer {{ civo_api_key }}"
register: civo_clusters
# - debug:
# msg: "{{ civo_clusters.json | community.general.json_query (list_query) }}"
- name: "Check if cluster exists"
set_fact:
cluster_exists: "{{ civo_clusters.json | community.general.json_query (clusters_list_query) | length == 1 }}"
# - debug:
# var: cluster_exists
# - fail:
# msg: "check point"
- name: "Create Cluster"
ansible.builtin.uri:
url: "{{ civo_api_url }}"
body:
name: "{{ civo_cluster_name}}"
applications: "-Traefik"
network_id: "{{ network_id }}"
firewall_rule: "{{ civo_firewall_rules }}"
kubernetes_version: "{{ civo_kubernetes_version }}"
num_target_nodes: "{{ civo_k3s_cluster_nodes }}"
region: "{{ civo_region }}"
target_nodes_size: "{{ civo_k3s_cluster_size }}"
body_format: json
return_content: yes
method: POST
headers:
Authorization: "bearer {{ civo_api_key }}"
when: not cluster_exists
register: cluster_create_result
# - debug:
# var: cluster_create_result
- name: "Wait for Cluster Creation"
ansible.builtin.uri:
url: "{{ civo_api_url }}/{{ cluster_create_result.json.id }}/?region={{ civo_region }}"
body_format: json
return_content: yes
headers:
Authorization: "bearer {{ civo_api_key }}"
register: cluster_active_result
retries: 20
delay: 30
until: cluster_active_result.json is defined and cluster_active_result.json.status == 'ACTIVE'
when: not cluster_exists
- debug:
var: cluster_active_result