-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeploy_master_openstack.yaml
207 lines (174 loc) · 5.78 KB
/
deploy_master_openstack.yaml
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
- name: Launch a compute instance
hosts: localhost
vars_files:
- openstack_config.yaml
environment:
OS_AUTH_URL: "{{ OS_AUTH_URL }}"
#OS_AUTH_TYPE: "{{ OS_AUTH_TYPE | default('password') }}"
OS_AUTH_TYPE: 'token'
OS_PROJECT_NAME: "{{ OS_PROJECT_NAME }}"
OS_PROJECT_ID: "{{ OS_PROJECT_ID }}"
OS_USERNAME: "{{ OS_USERNAME|default('NA') }}"
OS_REGION_NAME: "{{ OS_REGION_NAME }}"
OS_IDENTITY_API_VERSION: "{{ OS_IDENTITY_API_VERSION }}"
OS_CACERT: "{{ OS_CACERT }}"
tasks:
- name: Get OS token
environment:
OS_AUTH_URL: "{{ OS_AUTH_URL }}"
OS_AUTH_TYPE: "{{ OS_AUTH_TYPE }}"
OS_CACERT: "{{ OS_CACERT }}"
OS_USERNAME: "{{ OS_USERNAME | default() }}"
OS_PASSWORD: "{{ OS_PASSWORD | default() }}"
VOMS_PROXY: "{{ VOMS_PROXY | default() }}"
EGI_CHECKIN_URL: "{{ EGI_CHECKIN_URL | default() }}"
EGI_CHECKIN_CLIENT_ID: "{{ EGI_CHECKIN_CLIENT_ID | default() }}"
EGI_CHECKIN_CLIENT_SECRET: "{{ EGI_CHECKIN_CLIENT_SECRET | default()}}"
EGI_CHECKIN_REFRESH_TOKEN: "{{ EGI_CHECKIN_REFRESH_TOKEN | default() }}"
command: python roles/auth/keystone/files/keystone_client.py
register: token
- set_fact:
OS_AUTH_TYPE: 'token'
OS_TOKEN: "{{ (token.stdout|from_json).status.token }}"
OS_USERNAME: "{{ (token.stdout|from_json).user }}"
- name: Create the K8S security group
environment:
OS_AUTH_TYPE: 'token'
OS_TOKEN: "{{ OS_TOKEN }}"
block:
- name: Create the security group
os_security_group:
state: present
name: K8S-SG
description: security group for K8S cluster
- name: Add new rule to the K8S Security Group allowing any protocol
os_security_group_rule:
security_group: K8S-SG
protocol: "{{ item }}"
port_range_min: -1
port_range_max: -1
remote_ip_prefix: 0.0.0.0/0
with_items:
- tcp
- udp
- icmp
- name: Create the key pair with the specified public key
environment:
OS_AUTH_TYPE: 'token'
OS_TOKEN: "{{ OS_TOKEN }}"
os_keypair:
state: present
name: "{{ OS_KEY_NAME }}"
public_key_file: "{{ OS_KEY_PUBLIC }}"
when: OS_KEY_PUBLIC is defined
- name: Create the VM instance (public network with user defined ip)
when:
- OS_FIP is defined
- OS_FIP != "auto"
environment:
OS_AUTH_TYPE: 'token'
OS_TOKEN: "{{ OS_TOKEN }}"
block:
- name: Create the VM instance (public network with user defined ip)
os_server:
state: present
name: "{{ OS_MASTER_NAME }}"
image: "{{ OS_MASTER_IMAGE }}"
key_name: "{{ OS_KEY_NAME }}"
flavor: "{{ OS_MASTER_FLAVOR }}"
floating_ips: [ "{{ OS_FIP }}" ]
network: "{{ OS_NETWORK }}"
security_groups: "{{ OS_SECURITY_GROUP }}"
availability_zone: nova
reuse_ips: no
register: server
- set_fact:
K8S_MASTER_NAME: "{{ server.openstack.name }}"
K8S_MASTER_HOST: "{{ server.openstack.private_v4 }}"
when: server.openstack is defined
- name: Create the VM instance (public network with auto_ip)
when:
- OS_FIP is defined
- OS_FIP == "auto"
environment:
OS_AUTH_TYPE: 'token'
OS_TOKEN: "{{ OS_TOKEN }}"
block:
- name: Create the VM instance (public network with auto_ip)
os_server:
state: present
name: "{{ OS_MASTER_NAME }}"
image: "{{ OS_MASTER_IMAGE }}"
key_name: "{{ OS_KEY_NAME }}"
flavor: "{{ OS_MASTER_FLAVOR }}"
network: "{{ OS_NETWORK }}"
security_groups: "{{ OS_SECURITY_GROUP }}"
availability_zone: nova
auto_ip: yes
reuse_ips: yes
register: server
- set_fact:
K8S_MASTER_NAME: "{{ server.openstack.name }}"
K8S_MASTER_HOST: "{{ server.openstack.private_v4 }}"
OS_FIP: "{{ server.openstack.public_v4 }}"
when: server.openstack is defined
- name: Create the VM instance (private network)
when: OS_FIP is undefined
environment:
OS_AUTH_TYPE: 'token'
OS_TOKEN: "{{ OS_TOKEN }}"
block:
- name: Create the VM instance (private network)
os_server:
state: present
name: "{{ OS_MASTER_NAME }}"
image: "{{ OS_MASTER_IMAGE }}"
key_name: "{{ OS_KEY_NAME }}"
flavor: "{{ OS_MASTER_FLAVOR }}"
network: "{{ OS_NETWORK }}"
security_groups: "{{ OS_SECURITY_GROUP }}"
availability_zone: nova
reuse_ips: no
auto_ip: no
register: server
- set_fact:
K8S_MASTER_NAME: "{{ server.openstack.name }}"
K8S_MASTER_HOST: "{{ server.openstack.private_v4 }}"
when: server.openstack is defined
- name: Wait for SSH on the instance
command: >
ssh -i "{{ OS_KEY_PRIVATE }}" -o BatchMode=yes -o StrictHostKeyChecking=no ubuntu@"{{ OS_FIP | default(K8S_MASTER_HOST) }}" true
register: result
until: result is success
retries: 30
delay: 10
- name: Add VM to inventory
add_host:
name: "{{ K8S_MASTER_NAME }}"
groups: master
ansible_host: "{{ OS_FIP | default(K8S_MASTER_HOST) }}"
private_ip: "{{ K8S_MASTER_HOST }}"
ansible_ssh_private_key_file: "{{ OS_KEY_PRIVATE }}"
main_cluster_node: true
- name: Dump all vars
action: template src=templates/dump_vars.j2 dest=dump_vars.yaml
- name: Display vars
debug:
msg:
- "username: {{ OS_USERNAME }}"
- "token: {{ OS_TOKEN }}"
- name: Install Kubernetes
import_playbook: deploy_k8s.yaml
- name: Install Keystone authentication webhook and the nodes
gather_facts: false
hosts: master
remote_user: ubuntu
become: yes
become_method: sudo
vars_files:
- dump_vars.yaml
tasks:
- include_role:
name: auth/keystone
- include_role:
name: os-node