Added seed code for caas-lcm.
[ta/caas-lcm.git] / deploy / roles / clean_registry / 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: get the properties of the image:tag manifest
17   shell: "curl -i -H'Accept: application/vnd.docker.distribution.manifest.v2+json' {{ registry }}/v2/{{ image_name }}/manifests/{{ image_tag }}"
18   register: result
19
20 - fail:
21     msg: "{{ image_name }}/manifests/{{ image_tag }} manifest not found!"
22   when: ( result.stdout.find("MANIFEST_UNKNOWN") != -1)
23
24 - name: get the properties of the image:tag manifest
25   shell: "echo '{{ result.stdout }}' > /tmp/{{ image_name|replace('/', '_') }}_{{ image_tag }}.manifest"
26
27 - name: get the digest property
28   shell: grep Docker-Content-Digest /tmp/{{ image_name|replace('/', '_') }}_{{ image_tag }}.manifest | awk -F" " '{print $2}'
29   register: Docker_Content_Digest
30
31 - name: delete the manifest using the digest property
32   shell: "curl -XDELETE -H'Accept: application/vnd.docker.distribution.manifest.v2+json' {{ registry }}/v2/{{ image_name }}/manifests/{{ Docker_Content_Digest.stdout }}"
33
34 - name: get a registry pod id
35   shell: kubectl get pods -n kube-system | grep registry | grep Running | head -n 1 | awk -F" " '{print $1}'
36   register: registry_pod_id
37
38 - fail:
39     msg: "failure: no registry pod running"
40   when: ( registry_pod_id.stdout == "" )
41
42 - name: get the registry config file
43   shell: kubectl exec {{ registry_pod_id.stdout }} -c registry -n kube-system -- ps -o args | grep "registry serve" | awk -F'serve ' '{print $2}'
44   register: registry_config_file
45
46 - name: run the registry garbage collector
47   shell: kubectl exec {{ registry_pod_id.stdout }} -c registry -n kube-system -- /usr/bin/registry garbage-collect {{ registry_config_file.stdout }} > /tmp/{{ image_name|replace('/', '_') }}_{{ image_tag }}.gclog