62e103b85bb15febe83f2cf0e3cefd10e9d963d7
[ealt-edge.git] / ocd / infra / playbooks / roles / eg_mep / tasks / install.yml
1 # Copyright 2020 Huawei Technologies Co., Ltd.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 #
15
16 ---
17
18 - name: Doing deployment setup for edge gallery
19   copy:
20     src: deploy
21     dest: /tmp/eg_mep/
22
23 - name: Import config file
24   include_vars:
25     file: ../../../config.yml
26     name: vardata
27
28 - name: Remove old dir
29   command: rm -rf /tmp/.mep_tmp_cer
30   args:
31     chdir: /tmp/
32
33 - name: Make dir
34   command: mkdir -p /tmp/.mep_tmp_cer
35   args:
36     chdir: /tmp/
37
38 - name: Openssl genrsa
39   command: openssl genrsa -out ca.key 2048
40   args:
41     chdir: /tmp/.mep_tmp_cer/
42
43 - name: Opnessl req
44   # yamllint disable rule:line-length
45   command: openssl req -new -key ca.key -subj /C=CN/ST=Peking/L=Beijing/O=edgegallery/CN=edgegallery -out ca.csr
46   # yamllint disable rule:line-length
47   args:
48     chdir: /tmp/.mep_tmp_cer/
49
50 - name: Sing key with ca key and ca crt
51   # yamllint disable rule:line-length
52   command: openssl x509 -req -days 365 -in ca.csr -extensions v3_ca -signkey ca.key -out ca.crt
53   # yamllint disable rule:line-length
54   args:
55     chdir: /tmp/.mep_tmp_cer/
56
57 - name: Openssl genrsa
58   command: openssl genrsa -out mepserver_tls.key 2048
59   args:
60     chdir: /tmp/.mep_tmp_cer/
61
62 - name: Openssl rsa mep tls with common pwd
63   # yamllint disable rule:line-length
64   command: openssl rsa -in mepserver_tls.key -aes256 -passout pass:{{ vardata.common_pwd.name}} -out mepserver_encryptedtls.key
65   # yamllint disable rule:line-length
66   args:
67     chdir: /tmp/.mep_tmp_cer/
68   when: '{{ vardata.common_pwd.name}}'
69
70 - name: Openssl rsa mep tls
71   # yamllint disable rule:line-length
72   command: openssl rsa -in mepserver_tls.key -aes256 -passout pass:{{ vardata.mep_cert_pwd.name}} -out mepserver_encryptedtls.key
73   # yamllint disable rule:line-length
74   args:
75     chdir: /tmp/.mep_tmp_cer/
76   when: '{{ vardata.mep_cert_pwd.name}}'
77
78 - name: Openssl req new key mepserver tls key
79   # yamllint disable rule:line-length
80   command: openssl req -new -key mepserver_tls.key -subj /C=CN/ST=Beijing/L=Beijing/O=edgegallery/CN=edgegallery -out mepserver_tls.csr
81   # yamllint disable rule:line-length
82   args:
83     chdir: /tmp/.mep_tmp_cer/
84
85 - name: Openssl mepserver tls csr
86   # yamllint disable rule:line-length
87   command: openssl x509 -req -in mepserver_tls.csr -extensions v3_req -CA ca.crt -CAkey ca.key -CAcreateserial -out mepserver_tls.crt
88   # yamllint disable rule:line-length
89   args:
90     chdir: /tmp/.mep_tmp_cer/
91
92 - name: Openssl genrsa out
93   command: openssl genrsa -out jwt_privatekey 2048
94   args:
95     chdir: /tmp/.mep_tmp_cer/
96
97 - name: Openssl rsa jwt privatekey
98   command: openssl rsa -in jwt_privatekey -pubout -out jwt_publickey
99   args:
100     chdir: /tmp/.mep_tmp_cer/
101
102 - name: Openssl rsa in jwt with common pwd
103   # yamllint disable rule:line-length
104   command: openssl rsa -in jwt_privatekey -aes256 -passout pass:{{ vardata.common_pwd.name}} -out jwt_encrypted_privatekey
105   # yamllint disable rule:line-length
106   args:
107     chdir: /tmp/.mep_tmp_cer/
108   when: '{{ vardata.common_pwd.name}}'
109
110 - name: Openssl rsa in jwt
111   # yamllint disable rule:line-length
112   command: openssl rsa -in jwt_privatekey -aes256 -passout pass:{{ vardata.mep_cert_pwd.name}} -out jwt_encrypted_privatekey
113   # yamllint disable rule:line-length
114   args:
115     chdir: /tmp/.mep_tmp_cer/
116   when: '{{ vardata.mep_cert_pwd.name}}'
117
118 - name: Create mep namespace
119   command: kubectl create ns mep
120   args:
121     chdir: /tmp/
122
123 - name: Create generic pg secret with common pwd
124   # yamllint disable rule:line-length
125   command: kubectl -n mep create secret generic pg-secret --from-literal=pg_admin_pwd={{ vardata.common_pwd.name}} --from-literal=kong_pg_pwd={{ vardata.common_pwd.name}}
126            --from-file=server.key=/tmp/.mep_tmp_cer/mepserver_tls.key --from-file=server.crt=/tmp/.mep_tmp_cer/mepserver_tls.crt
127   # yamllint disable rule:line-length
128   args:
129     chdir: /tmp/
130   when: '{{ vardata.common_pwd.name}}'
131
132 - name: Create generic pg secret
133   # yamllint disable rule:line-length
134   command: kubectl -n mep create secret generic pg-secret --from-literal=pg_admin_pwd={{ vardata.mep_pg_admin_pwd.name}} --from-literal=kong_pg_pwd={{ vardata.mep_kong_pg_pwd.name}}
135            --from-file=server.key=/tmp/.mep_tmp_cer/mepserver_tls.key --from-file=server.crt=/tmp/.mep_tmp_cer/mepserver_tls.crt
136   # yamllint disable rule:line-length
137   args:
138     chdir: /tmp/
139   when: '{{ vardata.mep_pg_admin_pwd.name}}'
140
141 - name: Create mep generic for mep ssl with common pwd
142   # yamllint disable rule:line-length
143   command: kubectl -n mep create secret generic mep-ssl --from-literal=cert_pwd={{ vardata.common_pwd.name}} --from-file=server.cer=/tmp/.mep_tmp_cer/mepserver_tls.crt
144            --from-file=server_key.pem=/tmp/.mep_tmp_cer/mepserver_encryptedtls.key --from-file=trust.cer=/tmp/.mep_tmp_cer/ca.crt
145   # yamllint disable rule:line-length
146   args:
147     chdir: /tmp/
148   when: '{{ vardata.common_pwd.name}}'
149
150 - name: Create mep generic for mep ssl
151   # yamllint disable rule:line-length
152   command: kubectl -n mep create secret generic mep-ssl --from-literal=cert_pwd={{ vardata.mep_cert_pwd.name}} --from-file=server.cer=/tmp/.mep_tmp_cer/mepserver_tls.crt
153            --from-file=server_key.pem=/tmp/.mep_tmp_cer/mepserver_encryptedtls.key --from-file=trust.cer=/tmp/.mep_tmp_cer/ca.crt
154   # yamllint disable rule:line-length
155   args:
156     chdir: /tmp/
157   when: '{{ vardata.mep_cert_pwd.name}}'
158
159 - name: Create mep seret generic
160   # yamllint disable rule:line-length
161   command: kubectl -n mep create secret generic mepauth-secret --from-file=server.crt=/tmp/.mep_tmp_cer/mepserver_tls.crt --from-file=server.key=/tmp/.mep_tmp_cer/mepserver_tls.key
162            --from-file=ca.crt=/tmp/.mep_tmp_cer/ca.crt --from-file=jwt_publickey=/tmp/.mep_tmp_cer/jwt_publickey --from-file=jwt_encrypted_privatekey=/tmp/.mep_tmp_cer/jwt_encrypted_privatekey
163   # yamllint disable rule:line-length
164   args:
165     chdir: /tmp/
166
167 - name: Remove directory
168   command: rm -rf /tmp/.mep_tmp_cer
169   args:
170     chdir: /tmp/
171
172 - debug:
173     msg: Deploy_dns_metallb execution start
174
175 - name: Eg_Mep deployment execution of namesapce
176   command: kubectl apply -f /tmp/eg_mep/deploy/conf/edge/metallb/namespace.yaml
177   args:
178     chdir: /tmp/eg_mep/deploy/
179
180 - name: Eg_Mep deployment execution of metallb
181   command: kubectl apply -f /tmp/eg_mep/deploy/conf/edge/metallb/metallb.yaml
182   args:
183     chdir: /tmp/eg_mep/deploy/
184
185 - name: Eg_Mep deployment create secret
186   # yamllint disable rule:line-length
187   command: kubectl create secret generic -n metallb-system memberlist --from-literal=secretkey="$(openssl rand -base64 128)"
188   # yamllint disable rule:line-length
189   args:
190     chdir: /tmp/eg_mep/deploy/
191
192 - name: Eg_Mep deployment execution of config-mep
193   command: kubectl apply -f /tmp/eg_mep/deploy/conf/edge/metallb/config-map.yaml
194   args:
195     chdir: /tmp/eg_mep/deploy/
196
197 - debug:
198     msg: Deploy_network_isolation_multus execution start
199
200 - name: Running multus yaml files
201   command: kubectl apply -f /tmp/eg_mep/deploy/conf/edge/network-isolation/multus.yaml
202   args:
203     chdir: /tmp/eg_mep/deploy/
204
205 - name: Running eg-sp-rbac yaml files
206   command: kubectl apply -f /tmp/eg_mep/deploy/conf/edge/network-isolation/eg-sp-rbac.yaml
207   args:
208     chdir: /tmp/eg_mep/deploy/
209
210 - name: Replacing image
211   replace:
212     path: /tmp/eg_mep/deploy/conf/edge/network-isolation/eg-sp-controller.yaml
213     regexp: 'edgegallery/edgegallery-secondary-ep-controller:latest'
214     replace: "swr.ap-southeast-1.myhuaweicloud.com/edgegallery/edgegallery-secondary-ep-controller:latest"
215
216 - name: Running eg-sp-controller yaml files
217   # yamllint disable rule:line-length
218   command: kubectl apply -f /tmp/eg_mep/deploy/conf/edge/network-isolation/eg-sp-controller.yaml
219   args:
220     chdir: /tmp/eg_mep/deploy/
221
222 - debug:
223     msg: Setup_interfaces execution start
224
225 - name: Link eg mep macvlan
226   # yamllint disable rule:line-length
227   command: ip link add eg-mp1 link {{ vardata.edge_management_interface.name}} type macvlan mode bridge
228   args:
229     chdir: /tmp/eg_mep/deploy/
230   ignore_errors: yes
231   no_log: True
232
233 - name: Link eg mep macvlan
234   command: ip addr add {{ vardata.eg-management-address.name}} dev eg-mp1
235   args:
236     chdir: /tmp/eg_mep/deploy/
237   ignore_errors: yes
238   no_log: True
239
240 - name: Link eg me1 up
241   command: ip link set dev eg-mp1 up
242   args:
243     chdir: /tmp/eg_mep/deploy/
244   ignore_errors: yes
245   no_log: True
246
247 - name: Link eg eg mm5 with eth1
248   # yamllint disable rule:line-length
249   command: ip link add eg-mm5 link {{ vardata.edge_dataplane_interface.name}} type macvlan mode bridge
250   args:
251     chdir: /tmp/eg_mep/deploy/
252   ignore_errors: yes
253   no_log: True
254
255 - name: Link eg eg mm5 ip addr
256   command: ip addr add {{ vardata.eg-dataplane-address.name}} dev eg-mm5
257   args:
258     chdir: /tmp/eg_mep/deploy/
259   ignore_errors: yes
260   no_log: True
261
262 - name: Link eg eg mm5 set dev
263   command: ip link set dev eg-mm5 up
264   args:
265     chdir: /tmp/eg_mep/deploy/
266   ignore_errors: yes
267   no_log: True
268
269 - debug:
270     msg: Pull helm repo start
271
272 - name: Edge gallery mep installation pull chart and image
273   # yamllint disable rule:line-length
274   command: helm install mep-edgegallery edgegallery/mep --set networkIsolation.phyInterface.mp1={{ vardata.edge_management_interface.name}} --set networkIsolation.phyInterface.mm5={{ vardata.edge_dataplane_interface.name}} --set images.mep.repository={{ vardata.private_repo_ip.name}}:{{ vardata.docker_registry_port.name}}/edgegallery/mep --set images.mepauth.repository={{ vardata.private_repo_ip.name}}:{{ vardata.docker_registry_port.name}}/edgegallery/mepauth --set images.dns.repository={{ vardata.private_repo_ip.name}}:{{ vardata.docker_registry_port.name}}/edgegallery/mep-dns-server --set images.kong.repository={{ vardata.private_repo_ip.name}}:{{ vardata.docker_registry_port.name}}/kong --set images.postgres.repository={{ vardata.private_repo_ip.name}}:{{ vardata.docker_registry_port.name}}/postgres --set images.mep.tag={{ vardata.eg_image_tag.name}} --set images.mepauth.tag={{ vardata.eg_image_tag.name}} --set images.dns.tag={{ vardata.eg_image_tag.name}} --set images.mep.pullPolicy=IfNotPresent --set images.mepauth.pullPolicy=IfNotPresent --set images.dns.pullPolicy=IfNotPresent --set images.kong.pullPolicy=IfNotPresent --set images.postgres.pullPolicy=IfNotPresent --set ssl.secretName=mep-ssl
275   # yamllint disable rule:line-length