+---
+# ============LICENSE_START=======================================================
+# Copyright (C) 2019 The Nordix Foundation. All rights reserved.
+# ================================================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# SPDX-License-Identifier: Apache-2.0
+# ============LICENSE_END=========================================================
+
+- name: Get list of k8s container image tarfiles
+ find:
+ path: "{{ engine_workspace }}/offline/containers"
+ patterns: '*.tar'
+ register: container_image
+
+# NOTE (fdegir): the user may not be member of docker group so we need root
+# TODO (fdegir): we can perhaps skip loading already existing images here
+- name: Load k8s container images from tarfiles
+ shell: docker load < {{ item.path }}
+ loop: "{{ container_image.files }}"
+ changed_when: false
+ become: true
+
+# NOTE (fdegir): the escape of curly brackets in ansible is really messy unfortunately
+# we also shouldn't attempt to tag and push container images that are already on local registry
+# NOTE (fdegir): we do not push any image that is already on engine.local and any image without tag
+- name: Get list of loaded k8s container images to push
+ shell: |
+ set -o pipefail
+ docker images --format '{{ '{{' }}.Repository{{ '}}' }}':'{{ '{{' }}.Tag{{ '}}' }}' | grep -v '{{ server_fqdn }}\|<none>' | sort
+ args:
+ executable: /bin/bash
+ changed_when: false
+ become: true
+ register: container_images
+
+- name: Create dict of k8s container images to tag and push
+ set_fact:
+ container_images_dict: "{{ ( container_images_dict | default({}) ) | combine({item: item | regex_replace('.*?.io/', '')}) }}"
+ loop: "{{ container_images.stdout_lines }}"
+
+# TODO (fdegir): it is messy to use ansible module for tagging and pushing but we can still look into it
+# TODO (fdegir): we can perhaps skip tagging & pushing already existing images here
+- name: Tag and push k8s container images to local registry
+ shell: |
+ docker tag {{ item.key }} {{ server_fqdn }}/{{ item.value }}
+ docker push {{ server_fqdn }}/{{ item.value }}
+ with_dict: "{{ container_images_dict }}"
+ changed_when: false
+ become: true
+
+# vim: set ts=2 sw=2 expandtab: