Added seed code for caas-lcm.
[ta/caas-lcm.git] / su / roles / su_prepare / tasks / merge-charts.yml
1 ---
2 # Copyright 2019 Nokia
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 - name: fetch files from server which contains the necessary variables
17   fetch:
18     src: /etc/swift/usr/admin/admin.yml
19     dest: /tmp/
20     flat: yes
21
22 - name: register infos for swift_auth
23   set_fact:
24     swift_credential: "{{ lookup('file', '/tmp/admin.yml') | from_yaml }}"
25
26 - name: pause to wait for swift-update to be ready
27   pause:
28     minutes: 1
29
30 - name: authenticate on swift-upgrade
31   uri:
32     url: "{{ caas.swift_update }}/auth/v1.0"
33     headers:
34       X_Auth_User: admin:admin
35       X_Auth_Key: "{{ swift_credential.swift_password }}"
36   register: auth
37
38 - name: get packages
39   uri:
40     url: "{{ caas.swift_update }}/v1.0/AUTH_admin/packages"
41     return_content: yes
42     headers:
43       X_Auth_Token: "{{ auth.x_auth_token }}"
44   register: packages
45
46 - name: get charts from packages
47   set_fact:
48     charts: "{{ (packages.get('content','')|trim).split('\n') | select('search', 'charts.+\\.tgz') | list }}"
49
50 - name: get value files from packages
51   set_fact:
52     value_files: "{{ (packages.get('content','')|trim).split('\n') | select('search', 'releases.+\\.yaml') | list }}"
53   ignore_errors: yes
54
55 - name: create chart directory
56   file:
57     name: /tmp/su_chart
58     state: directory
59
60 - name: download charts
61   args:
62     chdir: /tmp/su_chart
63   command: "curl -O -XGET -H'X-Auth-Token: {{ auth.x_auth_token }}' {{ caas.swift_update }}/v1.0/AUTH_admin/packages/{{ item }}"
64   with_items: "{{ charts }}"
65
66 - name: download value files
67   args:
68     chdir: /tmp/su_chart
69   command: "curl -O -XGET -H'X-Auth-Token: {{ auth.x_auth_token }}' {{ caas.swift_update }}/v1.0/AUTH_admin/packages/{{ item }}"
70   with_items: "{{ value_files }}"
71   ignore_errors: yes
72
73 - name: upload charts via chart-repo
74   args:
75     chdir: /tmp/su_chart/
76   shell: "curl -sS -XPOST --cacert /etc/chart-repo/ssl/ca.pem --cert /etc/chart-repo/ssl/chart-repo?.pem --key /etc/chart-repo/ssl/chart-repo?-key.pem -H 'Content-Type: application/gzip' --data-binary @{{ item | basename }} {{ caas.chart_repo }}/{{ item }}"
77   with_items: "{{ charts }}"
78
79 - name: helm repo update
80   shell: helm repo update default {{ caas.chart_repo }}/charts
81
82 - name: authenticate on swift
83   uri:
84     url: "{{ caas.swift }}/auth/v1.0"
85     headers:
86       X_Auth_User: admin:admin
87       X_Auth_Key: "{{ swift_credential.swift_password }}"
88   register: auth_orig
89   ignore_errors: yes
90
91 - name: upload value file via swift
92   args:
93     chdir: /tmp/su_chart/
94   shell: "curl -XPUT -H 'X-Auth-Token: {{ auth_orig.x_auth_token }}' -T {{ item | basename }} {{ caas.swift }}/v1.0/AUTH_admin/packages/{{ item }}"
95   with_items: "{{ value_files }}"
96   ignore_errors: yes