Added seed code for caas-lcm.
[ta/caas-lcm.git] / deploy / roles / list_docker_images / tasks / list_docker_images.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: List docker images and tags
17   user: cloudadmin
18   hosts: "{{ groups.caas_master[0] | default('nowhere') }}"
19   connection: local
20   gather_facts: "False"
21   tasks:
22     - name: Get images
23       register: images_result
24       command: '/usr/bin/curl -sS
25         --key /etc/docker-registry/registry{{ nodeindex }}-key.pem
26         --cert /etc/docker-registry/registry{{ nodeindex }}.pem
27         {{ caas.registry }}/v2/_catalog'
28
29     - name: Get tags from image names
30       register: tags_result
31       command: '/usr/bin/curl -sS
32         --key /etc/docker-registry/registry{{ nodeindex }}-key.pem
33         --cert /etc/docker-registry/registry{{ nodeindex }}.pem
34         -H "Accept: application/vnd.docker.distribution.manifest.v2+json"
35         {{ caas.registry }}/v2/{{ item }}/tags/list'
36       with_items:
37         - "{{ (images_result.stdout|from_json).repositories }}"
38
39     - name: List of image names and tags
40       set_fact:
41         image_names_and_tags: {}
42
43     - name: Create images names and tags dictionary
44       set_fact:
45         image_names_and_tags: "{{ image_names_and_tags|combine( {(item.stdout|from_json).name: (item.stdout|from_json).tags} ) }}"
46       with_items:
47         - "{{ tags_result.results }}"
48
49     - name: Create a json from list of docker images and tags
50       template:
51         src: "return_value_list_docker_images.j2"
52         dest: "/tmp/return_value_list_docker_images.json"