-
Notifications
You must be signed in to change notification settings - Fork 0
/
ansible2
116 lines (108 loc) · 4.68 KB
/
ansible2
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
- name: PowerOn bootstrap server
community.vmware.vmware_guest_powerstate:
hostname: "{{ vcenter | json_query('datacenters[?dc_iden == `_host.datacenter` | default(default_datacenter_id)] | [0].hostname') | first }}"
username: "{{ vcenter.username }}"
password: "{{ vcenter.password }}"
validate_certs: false
folder: "{{ vcenter | json_query('datacenters[?dc_iden == `_host.datacenter` | default(default_datacenter_id)] | [0].folder') | first }}{{ cluster_name | upper }}"
name: "{{ _host.hostname }}.{{ cluster_name }}.{{ base_domain }}"
state: powered-on
vars:
_host: "{{ hosts.values() | selectattr('role', 'equalto', 'bootstrap') | last | first }}"
when:
- _host.enabled | default('true') | bool
- name: Wait for API
uri:
url: https://api.{{ cluster_name }}.{{ base_domain }}:6443/readyz
method: GET
validate_certs: false
return_content: yes
timeout: 5
register: api_ready
until: api_ready.content == "ok"
retries: "{{ api_time_wait | default(300) }}"
delay: 5
- name: PowerOn all master servers
community.vmware.vmware_guest_powerstate:
hostname: "{{ vcenter | json_query('datacenters[?dc_iden == `_host.datacenter` | default(default_datacenter_id)] | [0].hostname') }}"
username: "{{ vcenter.username }}"
password: "{{ vcenter.password }}"
validate_certs: false
folder: "{{ vcenter | json_query('datacenters[?dc_iden == `_host.datacenter` | default(default_datacenter_id)] | [0].folder') }}"
name: "{{ _host.hostname }}.{{ cluster_name }}.{{ base_domain }}"
state: powered-on
vars:
_host: "{{ hosts.values() | selectattr('role', 'equalto', 'master') | list }}"
loop_control:
label: Power on host {{ _host.hostname }}
when:
- _host.enabled | default('true') | bool
- name: Wait for all master is UP
uri:
url: https://api.{{ cluster_name }}.{{ base_domain }}:6443/api/v1/nodes
method: GET
validate_certs: false
return_content: yes
client_certs: "{{ _client_cert }}"
status_codes: 200,201,204
vars:
_client_cert: "{{ tmp_path_prefix }}/{{ install_dir }}/auth/client_cert.pem"
register: ready_master
until: (ready_master.content | from_json | json_query('items[*].status.conditions[?reason=="KubeletReady" && status=="True"]').length == {{ api_time_wait | default(300) }})
delay: 5
when: initialize_cluster | bool
- name: PowerOn other servers
community.vmware.vmware_guest_powerstate:
hostname: "{{ vcenter | json_query('datacenters[?dc_iden == `_host.datacenter` | default(default_datacenter_id)] | [0].hostname') }}"
username: "{{ vcenter.username }}"
password: "{{ vcenter.password }}"
validate_certs: false
folder: "{{ vcenter | json_query('datacenters[?dc_iden == `_host.datacenter` | default(default_datacenter_id)] | [0].folder') }}"
name: "{{ _host.hostname }}.{{ cluster_name }}.{{ base_domain }}"
state: powered-on
vars:
_host: "{{ item }}"
loop: "{{ hosts.values() | rejectattr('role', 'match', 'master|bootstrap') | list }}"
loop_control:
label: Power on host {{ _host.hostname }}
- name: Configure cluster mode
block:
- name: Get Credentials
include_tasks:
file: tasks/get_cred.yml
- name: Configure additional labels for nodes
uri:
url: https://api.{{ cluster_name }}.{{ base_domain }}:6443/api/v1/nodes/{{ item.hostname }}
validate_certs: false
method: PATCH
headers:
Content-Type: application/merge-patch+json
client_cert: "{{ client_cert_file.dest }}"
status_codes: 200,201,204
body_format: json
body: "{{ { 'metadata': { 'labels': _labels } } }}"
vars:
_labels: "{{ item.labels | from_yaml | to_json | from_json }}"
loop: "{{ hosts.values() | selectattr('role', 'match', 'bootstrap') | selectattr('labels', 'defined') | list }}"
loop_control:
label: Configure additional labels for node {{ item.hostname }}
when: _labels | length > 0
ignore_errors: yes
- name: Configure specification for nodes
uri:
url: https://api.{{ cluster_name }}.{{ base_domain }}:6443/api/v1/nodes/{{ item.hostname }}
validate_certs: false
method: PATCH
headers:
Content-Type: application/merge-patch+json
client_cert: "{{ client_cert_file.dest }}"
status_codes: 200,201,204
body_format: json
body: "{{ { 'spec': _spec } }}"
vars:
_spec: "{{ item.spec | from_yaml | to_json | from_json }}"
loop: "{{ hosts.values() | selectattr('role', 'ne', 'bootstrap') | selectattr('spec', 'defined') | list }}"
loop_control:
label: Configure spec for node {{ item.hostname }}
when: _spec | length > 0
ignore_errors: yes