Added seed code for caas-lcm.
[ta/caas-lcm.git] / deploy / roles / clean_chart / tasks / main.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: src={{ item }} dest=/tmp/ flat=yes
18   with_items:
19     - /etc/swift/usr/admin/admin.yml
20
21 - name: register infos for swift_auth
22   set_fact:
23     swift_credential: "{{ lookup('file', swift_admin_path + '/admin.yml') | from_yaml }}"
24
25 - name: authenticate on swift
26   uri:
27     url: "{{ caas.swift }}/auth/v1.0"
28     headers:
29       X_Auth_User: admin:admin
30       X_Auth_Key: "{{ swift_credential.swift_password }}"
31   register: auth
32
33 - name: clean charts list file if exists
34   file:
35     path: /tmp/charts_list
36     state: absent
37
38 - name: get current charts list
39   shell: "curl -H'X_Auth_Token: {{ auth.x_auth_token }}' {{ caas.swift }}/v1.0/AUTH_admin/packages > /tmp/charts_list"
40
41 - name: chart_pattern
42   set_fact:
43     chart_pattern: "{{ chart_name | replace('*', '.*') }}"
44
45 - name: version_pattern
46   set_fact:
47     version_pattern: "{{ chart_version | replace('*', '[0-9]+') }}"
48
49 - name: search
50   shell: cat /tmp/charts_list | egrep "charts/{{ chart_pattern }}-[0-9]+\.[0-9]+\.[0-9]+" | egrep "{{ version_pattern }}\.tgz"
51   register: chart_matched
52
53 - name: delete the chart from swift
54   shell: "curl -XDELETE {{ caas.chart_repo }}/{{ item }}"
55   with_items: "{{ chart_matched.stdout_lines }}"
56
57 - name: helm repo update
58   shell: helm repo update default {{ caas.chart_repo }}/charts
59