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: Create directory to store container images
22 path: "{{ containers_folder }}"
28 - name: Set versions of k8s components in Kubespray downloads role
30 path: "{{ git_folder }}/kubespray/roles/download/defaults/main.yml"
31 regexp: "{{ item.regexp }}"
32 line: "{{ item.line }}"
34 - {regexp: "^kube_version:.*", line: "kube_version: {{ kubernetes_version }}"}
35 - {regexp: "^helm_version:.*", line: "helm_version: {{ helm_version }}"}
37 # NOTE (fdegir): order of vars files is significant
38 - name: Include kubespray vars files
39 include_vars: "{{ item }}"
41 - "{{ git_folder }}/kubespray/roles/kubespray-defaults/defaults/main.yaml"
42 - "{{ git_folder }}/kubespray/roles/download/defaults/main.yml"
44 - name: Remove outdated kubeadm-images.yaml file
46 path: "/tmp/kubeadm-images.yaml"
49 - name: Generate kubeadm-images.yaml to fetch container images
51 src: "kubeadm-images.yaml.j2"
52 dest: "/tmp/kubeadm-images.yaml"
55 # NOTE (fdegir): the tasks below are taken from kubespray/roles/download/tasks/prep_kubeadm_images.yml
56 - name: Get list of kubeadm images
59 {{ binaries_folder }}/kubeadm config images list --config=/tmp/kubeadm-images.yaml | grep -v coredns
62 register: kubeadm_images_raw
66 - name: Parse list of kubeadm images
68 kubeadm_images_list: "{{ kubeadm_images_raw.stdout_lines }}"
71 key: "kubeadm_{{ (item | regex_replace('^(?:.*\\/)*','')).split(':')[0] }}"
75 repo: "{{ item | regex_replace('^(.*):.*$','\\1') }}"
76 tag: "{{ item | regex_replace('^.*:(.*)$','\\1') }}"
77 loop: "{{ kubeadm_images_list | flatten(levels=1) }}"
78 register: kubeadm_images_cooked
81 - name: Convert list of kubeadm images to dict
83 kubeadm_images: "{{ kubeadm_images_cooked.results | map(attribute='ansible_facts.kubeadm_image') | list | items2dict }}"
86 - name: Populate list of images to pull and save with those specified by Kubespray
90 image_list: "{{ image_list }} + [ '{{ downloads[item].repo }}:{{ downloads[item].tag }}' ]"
91 loop: "{{ k8s_misc_images }}"
93 when: downloads[item].container is defined and downloads[item].container
95 - name: Populate list of images to pull and save with those specified by Kubeadm
97 image_list: "{{ image_list }} + [ '{{ item.value.repo }}:{{ item.value.tag }}' ]"
98 loop: "{{ kubeadm_images | dict2items }}"
101 - name: Populate list of images to pull and save with other miscellaneous images
103 image_list: "{{ image_list }} + [ '{{ item.value.repo }}:{{ item.value.tag }}' ]"
104 loop: "{{ other_images | dict2items }}"
107 - name: Add tiller container image to list of images (helm v2 only)
109 image_list: "{{ image_list }} + [ '{{ downloads['tiller'].repo }}:{{ downloads['tiller'].tag }}' ]"
111 when: helm_version is version('v3.0.0', '<')
113 - name: Dump image list to disk
115 content: "{{ image_list | join('\n') }}"
116 dest: "{{ engine_cache }}/images.txt"
118 - name: Pull images (using pull-images.sh)
120 container_tool: docker
121 container_pull_parallel: 4
122 images_txt: "{{ engine_cache }}/images.txt"
123 script: pull-images.sh -l {{ images_txt }} -c {{ container_tool }} -p {{ container_pull_parallel }}
125 register: pull_images_output_raw
126 changed_when: pull_images_output_raw.stdout is search("downloaded newer image for", ignorecase=true)
128 - name: Save images (using save-images.sh)
130 container_tool: docker
131 images_txt: "{{ engine_cache }}/images.txt"
132 images_output: "{{ containers_folder }}/images.tar"
133 script: save-images.sh -l {{ images_txt }} -c {{ container_tool }} -o {{ images_output }}
135 creates: "{{ images_output }}"
138 - name: Save registry image separately
140 img: "{{ other_images['docker-registry'].repo }}:{{ other_images['docker-registry'].tag }}"
141 dest: "{{ img | regex_replace('[/:]', '_') }}.tar"
144 docker save {{ img }} -o {{ dest }}
146 executable: "/bin/bash"
147 chdir: "{{ containers_folder }}"
148 creates: "{{ containers_folder }}/{{ dest }}"
151 # NOTE (fdegir): archive fails due to wrong permissions so we fix them
152 - name: Fix container image permissions
154 path: "{{ containers_folder }}"
160 # vim: set ts=2 sw=2 expandtab: