2 # ============LICENSE_START=======================================================
3 # Copyright (C) 2019 The Nordix Foundation. All rights reserved.
4 # ================================================================================
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # SPDX-License-Identifier: Apache-2.0
18 # ============LICENSE_END=========================================================
20 - name: Get list of k8s container image tarfiles
22 path: "{{ engine_workspace }}/offline/containers"
24 register: container_image
26 # NOTE (fdegir): the user may not be member of docker group so we need root
27 # TODO (fdegir): we can perhaps skip loading already existing images here
28 - name: Load k8s container images from tarfiles
29 shell: docker load < {{ item.path }}
30 loop: "{{ container_image.files }}"
34 # NOTE (fdegir): the escape of curly brackets in ansible is really messy unfortunately
35 # we also shouldn't attempt to tag and push container images that are already on local registry
36 # NOTE (fdegir): we do not push any image that is already on engine.local and any image without tag
37 - name: Get list of loaded k8s container images to push
40 docker images --format '{{ '{{' }}.Repository{{ '}}' }}':'{{ '{{' }}.Tag{{ '}}' }}' | grep -v '{{ server_fqdn }}\|<none>' | sort
45 register: container_images
47 - name: Create dict of k8s container images to tag and push
49 container_images_dict: "{{ ( container_images_dict | default({}) ) | combine({item: item | regex_replace('.*?.io/', '')}) }}"
50 loop: "{{ container_images.stdout_lines }}"
52 # TODO (fdegir): it is messy to use ansible module for tagging and pushing but we can still look into it
53 # TODO (fdegir): we can perhaps skip tagging & pushing already existing images here
54 - name: Tag and push k8s container images to local registry
56 docker tag {{ item.key }} {{ server_fqdn }}/{{ item.value }}
57 docker push {{ server_fqdn }}/{{ item.value }}
58 with_dict: "{{ container_images_dict }}"
62 # vim: set ts=2 sw=2 expandtab: