Edge gallery roles added
[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
63   # yamllint disable rule:line-length
64   command: openssl rsa -in mepserver_tls.key -aes256 -passout pass:{{ vardata.generate_cert_pass.name}} -out mepserver_encryptedtls.key
65   # yamllint disable rule:line-length
66   args:
67     chdir: /tmp/.mep_tmp_cer/
68
69 - name: Openssl req new key mepserver tls key
70   # yamllint disable rule:line-length
71   command: openssl req -new -key mepserver_tls.key -subj /C=CN/ST=Beijing/L=Beijing/O=edgegallery/CN=edgegallery -out mepserver_tls.csr
72   # yamllint disable rule:line-length
73   args:
74     chdir: /tmp/.mep_tmp_cer/
75
76 - name: Openssl mepserver tls csr
77   # yamllint disable rule:line-length
78   command: openssl x509 -req -in mepserver_tls.csr -extensions v3_req -CA ca.crt -CAkey ca.key -CAcreateserial -out mepserver_tls.crt
79   # yamllint disable rule:line-length
80   args:
81     chdir: /tmp/.mep_tmp_cer/
82
83 - name: Openssl genrsa out
84   command: openssl genrsa -out jwt_privatekey 2048
85   args:
86     chdir: /tmp/.mep_tmp_cer/
87
88 - name: Openssl rsa jwt privatekey
89   command: openssl rsa -in jwt_privatekey -pubout -out jwt_publickey
90   args:
91     chdir: /tmp/.mep_tmp_cer/
92
93 - name: Openssl rsa in jwt
94   # yamllint disable rule:line-length
95   command: openssl rsa -in jwt_privatekey -aes256 -passout pass:{{ vardata.generate_cert_pass.name}} -out jwt_encrypted_privatekey
96   # yamllint disable rule:line-length
97   args:
98     chdir: /tmp/.mep_tmp_cer/
99
100 - name: Create mep namespace
101   command: kubectl create ns mep
102   args:
103     chdir: /tmp/
104
105 - name: Create generic pg secret
106   # yamllint disable rule:line-length
107   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}}
108            --from-file=server.key=/tmp/.mep_tmp_cer/mepserver_tls.key --from-file=server.crt=/tmp/.mep_tmp_cer/mepserver_tls.crt
109   # yamllint disable rule:line-length
110   args:
111     chdir: /tmp/
112
113 - name: Create mep generic for mep ssl
114   # yamllint disable rule:line-length
115   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
116            --from-file=server_key.pem=/tmp/.mep_tmp_cer/mepserver_encryptedtls.key --from-file=trust.cer=/tmp/.mep_tmp_cer/ca.crt
117   # yamllint disable rule:line-length
118   args:
119     chdir: /tmp/
120
121 - name: Create mep seret generic
122   # yamllint disable rule:line-length
123   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
124            --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
125   # yamllint disable rule:line-length
126   args:
127     chdir: /tmp/
128
129 - name: Remove directory
130   command: rm -rf /tmp/.mep_tmp_cer
131   args:
132     chdir: /tmp/
133
134 - debug:
135     msg: Deploy_dns_metallb execution start
136
137 - name: Eg_Mep deployment execution of namesapce
138   command: kubectl apply -f /tmp/eg_mep/deploy/conf/edge/metallb/namespace.yaml
139   args:
140     chdir: /tmp/eg_mep/deploy/
141
142 - name: Eg_Mep deployment execution of metallb
143   command: kubectl apply -f /tmp/eg_mep/deploy/conf/edge/metallb/metallb.yaml
144   args:
145     chdir: /tmp/eg_mep/deploy/
146
147 - name: Eg_Mep deployment create secret
148   # yamllint disable rule:line-length
149   command: kubectl create secret generic -n metallb-system memberlist --from-literal=secretkey="$(openssl rand -base64 128)"
150   # yamllint disable rule:line-length
151   args:
152     chdir: /tmp/eg_mep/deploy/
153
154 - name: Eg_Mep deployment execution of config-mep
155   command: kubectl apply -f /tmp/eg_mep/deploy/conf/edge/metallb/config-map.yaml
156   args:
157     chdir: /tmp/eg_mep/deploy/
158
159 - debug:
160     msg: Deploy_network_isolation_multus execution start
161
162 - name: Running multus yaml files
163   command: kubectl apply -f /tmp/eg_mep/deploy/conf/edge/network-isolation/multus.yaml
164   args:
165     chdir: /tmp/eg_mep/deploy/
166
167 - name: Running eg-sp-rbac yaml files
168   command: kubectl apply -f /tmp/eg_mep/deploy/conf/edge/network-isolation/eg-sp-rbac.yaml
169   args:
170     chdir: /tmp/eg_mep/deploy/
171
172 - name: Replacing image
173   replace:
174     path: /tmp/eg_mep/deploy/conf/edge/network-isolation/eg-sp-controller.yaml
175     regexp: 'edgegallery/edgegallery-secondary-ep-controller:latest'
176     replace: "swr.ap-southeast-1.myhuaweicloud.com/edgegallery/edgegallery-secondary-ep-controller:latest"
177
178 - name: Running eg-sp-controller yaml files
179   # yamllint disable rule:line-length
180   command: kubectl apply -f /tmp/eg_mep/deploy/conf/edge/network-isolation/eg-sp-controller.yaml
181   args:
182     chdir: /tmp/eg_mep/deploy/
183
184 - debug:
185     msg: Setup_interfaces execution start
186
187 - name: Link eg mep macvlan
188   # yamllint disable rule:line-length
189   command: ip link add eg-mp1 link {{ vardata.system_interfaceeth1.name}} type macvlan mode bridge
190   args:
191     chdir: /tmp/eg_mep/deploy/
192   ignore_errors: yes
193   no_log: True
194
195 - name: Link eg mep macvlan
196   command: ip addr add {{ vardata.mep_ip_addr_macvlan_eg_mep1.name}} dev eg-mp1
197   args:
198     chdir: /tmp/eg_mep/deploy/
199   ignore_errors: yes
200   no_log: True
201
202 - name: Link eg me1 up
203   command: ip link set dev eg-mp1 up
204   args:
205     chdir: /tmp/eg_mep/deploy/
206   ignore_errors: yes
207   no_log: True
208
209 - name: Link eg eg mm5 with eth1
210   # yamllint disable rule:line-length
211   command: ip link add eg-mm5 link {{ vardata.system_interfaceeth2.name}} type macvlan mode bridge
212   args:
213     chdir: /tmp/eg_mep/deploy/
214   ignore_errors: yes
215   no_log: True
216
217 - name: Link eg eg mm5 ip addr
218   command: ip addr add {{ vardata.mep_ip_addr_mm5_eg_mm5.name}} dev eg-mm5
219   args:
220     chdir: /tmp/eg_mep/deploy/
221   ignore_errors: yes
222   no_log: True
223
224 - name: Link eg eg mm5 set dev
225   command: ip link set dev eg-mm5 up
226   args:
227     chdir: /tmp/eg_mep/deploy/
228   ignore_errors: yes
229   no_log: True
230
231 - debug:
232     msg: Pull helm repo start
233
234 - name: Edge gallery mep installation pull chart and image
235   # yamllint disable rule:line-length
236   command: helm install mep-edgegallery edgegallery/mep --set networkIsolation.phyInterface.mp1={{ vardata.system_interfaceeth1.name}} --set networkIsolation.phyInterface.mm5={{ vardata.system_interfaceeth2.name}} --set images.mep.tag={{ vardata.mep_image_tag.name}} --set images.mepauth.tag={{ vardata.mep_mepauth_image_tag.name}} --set images.dns.tag={{ vardata.mep_dns_image_tag.name}} --set ssl.secretName=mep-ssl
237   # yamllint disable rule:line-length