X-Git-Url: https://gerrit.nordix.org/gitweb?p=infra%2Fstack%2Fkubernetes.git;a=blobdiff_plain;f=playbooks%2Froles%2Fprepare-artifacts%2Ftasks%2Fmain.yaml;fp=playbooks%2Froles%2Fprepare-artifacts%2Ftasks%2Fmain.yaml;h=f55b04408a597328d471e56665fd26013bc27e8b;hp=0000000000000000000000000000000000000000;hb=20d34e772e021fabdee0aa9b50e9804a80d5108a;hpb=0ee637017774692ae73514e146f25c8973c3bffe diff --git a/playbooks/roles/prepare-artifacts/tasks/main.yaml b/playbooks/roles/prepare-artifacts/tasks/main.yaml new file mode 100644 index 0000000..f55b044 --- /dev/null +++ b/playbooks/roles/prepare-artifacts/tasks/main.yaml @@ -0,0 +1,62 @@ +--- +# ============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 }}\|' | 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: