| --- |
| # ============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: Create directory to store container images |
| file: |
| path: "{{ containers_folder }}" |
| state: "{{ item }}" |
| with_items: |
| - absent |
| - directory |
| |
| - name: Set versions of k8s components in Kubespray downloads role |
| lineinfile: |
| path: "{{ git_folder }}/kubespray/roles/download/defaults/main.yml" |
| regexp: "{{ item.regexp }}" |
| line: "{{ item.line }}" |
| with_items: |
| - {regexp: "^kube_version:.*", line: "kube_version: {{ kubernetes_version }}"} |
| - {regexp: "^helm_version:.*", line: "helm_version: {{ helm_version }}"} |
| |
| # NOTE (fdegir): order of vars files is significant |
| - name: Include kubespray vars files |
| include_vars: "{{ item }}" |
| with_items: |
| - "{{ git_folder }}/kubespray/roles/kubespray-defaults/defaults/main.yaml" |
| - "{{ git_folder }}/kubespray/roles/download/defaults/main.yml" |
| |
| - name: Remove outdated kubeadm-images.yaml file |
| file: |
| path: "/tmp/kubeadm-images.yaml" |
| state: absent |
| |
| - name: Generate kubeadm-images.yaml to fetch container images |
| template: |
| src: "kubeadm-images.yaml.j2" |
| dest: "/tmp/kubeadm-images.yaml" |
| force: true |
| |
| # NOTE (fdegir): the tasks below are taken from kubespray/roles/download/tasks/prep_kubeadm_images.yml |
| - name: Get list of kubeadm images |
| shell: | |
| set -o pipefail |
| {{ binaries_folder }}/kubeadm config images list --config=/tmp/kubeadm-images.yaml | grep -v coredns |
| args: |
| executable: /bin/bash |
| register: kubeadm_images_raw |
| run_once: true |
| changed_when: false |
| |
| - name: Parse list of kubeadm images |
| vars: |
| kubeadm_images_list: "{{ kubeadm_images_raw.stdout_lines }}" |
| set_fact: |
| kubeadm_image: |
| key: "kubeadm_{{ (item | regex_replace('^(?:.*\\/)*','')).split(':')[0] }}" |
| value: |
| enabled: true |
| container: true |
| repo: "{{ item | regex_replace('^(.*):.*$','\\1') }}" |
| tag: "{{ item | regex_replace('^.*:(.*)$','\\1') }}" |
| loop: "{{ kubeadm_images_list | flatten(levels=1) }}" |
| register: kubeadm_images_cooked |
| run_once: true |
| |
| - name: Convert list of kubeadm images to dict |
| set_fact: |
| kubeadm_images: "{{ kubeadm_images_cooked.results | map(attribute='ansible_facts.kubeadm_image') | list | items2dict }}" |
| run_once: true |
| |
| # NOTE (fdegir): docker_image module doesn't seem to respect become so falling back to command module |
| - name: Pull kubeadm container images |
| command: "docker pull {{ kubeadm_images[item.key].repo }}:{{ kubeadm_images[item.key].tag }}" |
| with_dict: "{{ kubeadm_images }}" |
| become: true |
| changed_when: false |
| |
| - name: Pull misc container images |
| command: "docker pull {{ downloads[item].repo }}:{{ downloads[item].tag }}" |
| loop: "{{ k8s_misc_images }}" |
| become: true |
| changed_when: false |
| |
| - name: Pull other container images |
| command: "docker pull {{ other_images[item.key].repo }}:{{ other_images[item.key].tag }}" |
| with_dict: "{{ other_images }}" |
| become: true |
| changed_when: false |
| |
| # save container images |
| - name: Save kubeadm container images |
| command: |- |
| docker save {{ kubeadm_images[item.key].repo }}:{{ kubeadm_images[item.key].tag }} |
| -o {{ kubeadm_images[item.key].repo | replace('/', '_') }}_{{ kubeadm_images[item.key].tag }}.tar |
| with_dict: "{{ kubeadm_images }}" |
| args: |
| chdir: "{{ containers_folder }}" |
| become: true |
| changed_when: false |
| |
| - name: Save misc container images |
| command: |- |
| docker save {{ downloads[item].repo }}:{{ downloads[item].tag }} |
| -o {{ downloads[item].repo }} -o {{ downloads[item].repo | replace('/', '_') }}_{{ downloads[item].tag }}.tar |
| loop: "{{ k8s_misc_images }}" |
| args: |
| chdir: "{{ containers_folder }}" |
| become: true |
| changed_when: false |
| |
| - name: Save other container images |
| command: |- |
| docker save {{ other_images[item.key].repo }}:{{ other_images[item.key].tag }} |
| -o {{ other_images[item.key].repo | replace('/', '_') }}_{{ other_images[item.key].tag }}.tar |
| with_dict: "{{ other_images }}" |
| args: |
| chdir: "{{ containers_folder }}" |
| become: true |
| changed_when: false |
| |
| # NOTE (fdegir): archive fails due to wrong permissions so we fix them |
| - name: Fix container image permissions |
| file: |
| path: "{{ containers_folder }}" |
| state: directory |
| recurse: true |
| mode: 0755 |
| become: true |
| |
| # vim: set ts=2 sw=2 expandtab: |