Fatih Degirmenci | 20d34e7 | 2020-05-19 08:13:26 +0000 | [diff] [blame] | 1 | --- |
| 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 |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 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. |
| 16 | # |
| 17 | # SPDX-License-Identifier: Apache-2.0 |
| 18 | # ============LICENSE_END========================================================= |
| 19 | |
| 20 | - name: Create directory to store container images |
| 21 | file: |
| 22 | path: "{{ containers_folder }}" |
| 23 | state: "{{ item }}" |
| 24 | with_items: |
| 25 | - absent |
| 26 | - directory |
| 27 | |
| 28 | - name: Set versions of k8s components in Kubespray downloads role |
| 29 | lineinfile: |
| 30 | path: "{{ git_folder }}/kubespray/roles/download/defaults/main.yml" |
| 31 | regexp: "{{ item.regexp }}" |
| 32 | line: "{{ item.line }}" |
| 33 | with_items: |
| 34 | - {regexp: "^kube_version:.*", line: "kube_version: {{ kubernetes_version }}"} |
| 35 | - {regexp: "^helm_version:.*", line: "helm_version: {{ helm_version }}"} |
| 36 | |
| 37 | # NOTE (fdegir): order of vars files is significant |
| 38 | - name: Include kubespray vars files |
| 39 | include_vars: "{{ item }}" |
| 40 | with_items: |
| 41 | - "{{ git_folder }}/kubespray/roles/kubespray-defaults/defaults/main.yaml" |
| 42 | - "{{ git_folder }}/kubespray/roles/download/defaults/main.yml" |
| 43 | |
| 44 | - name: Remove outdated kubeadm-images.yaml file |
| 45 | file: |
| 46 | path: "/tmp/kubeadm-images.yaml" |
| 47 | state: absent |
| 48 | |
| 49 | - name: Generate kubeadm-images.yaml to fetch container images |
| 50 | template: |
| 51 | src: "kubeadm-images.yaml.j2" |
| 52 | dest: "/tmp/kubeadm-images.yaml" |
| 53 | force: true |
| 54 | |
| 55 | # NOTE (fdegir): the tasks below are taken from kubespray/roles/download/tasks/prep_kubeadm_images.yml |
| 56 | - name: Get list of kubeadm images |
| 57 | shell: | |
| 58 | set -o pipefail |
| 59 | {{ binaries_folder }}/kubeadm config images list --config=/tmp/kubeadm-images.yaml | grep -v coredns |
| 60 | args: |
| 61 | executable: /bin/bash |
| 62 | register: kubeadm_images_raw |
| 63 | run_once: true |
| 64 | changed_when: false |
| 65 | |
| 66 | - name: Parse list of kubeadm images |
| 67 | vars: |
| 68 | kubeadm_images_list: "{{ kubeadm_images_raw.stdout_lines }}" |
| 69 | set_fact: |
| 70 | kubeadm_image: |
| 71 | key: "kubeadm_{{ (item | regex_replace('^(?:.*\\/)*','')).split(':')[0] }}" |
| 72 | value: |
| 73 | enabled: true |
| 74 | container: true |
| 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 |
| 79 | run_once: true |
| 80 | |
| 81 | - name: Convert list of kubeadm images to dict |
| 82 | set_fact: |
| 83 | kubeadm_images: "{{ kubeadm_images_cooked.results | map(attribute='ansible_facts.kubeadm_image') | list | items2dict }}" |
| 84 | run_once: true |
| 85 | |
| 86 | # NOTE (fdegir): docker_image module doesn't seem to respect become so falling back to command module |
| 87 | - name: Pull kubeadm container images |
| 88 | command: "docker pull {{ kubeadm_images[item.key].repo }}:{{ kubeadm_images[item.key].tag }}" |
| 89 | with_dict: "{{ kubeadm_images }}" |
| 90 | become: true |
| 91 | changed_when: false |
| 92 | |
| 93 | - name: Pull misc container images |
| 94 | command: "docker pull {{ downloads[item].repo }}:{{ downloads[item].tag }}" |
| 95 | loop: "{{ k8s_misc_images }}" |
| 96 | become: true |
| 97 | changed_when: false |
| 98 | |
| 99 | - name: Pull other container images |
| 100 | command: "docker pull {{ other_images[item.key].repo }}:{{ other_images[item.key].tag }}" |
| 101 | with_dict: "{{ other_images }}" |
| 102 | become: true |
| 103 | changed_when: false |
| 104 | |
| 105 | # save container images |
| 106 | - name: Save kubeadm container images |
| 107 | command: |- |
| 108 | docker save {{ kubeadm_images[item.key].repo }}:{{ kubeadm_images[item.key].tag }} |
| 109 | -o {{ kubeadm_images[item.key].repo | replace('/', '_') }}_{{ kubeadm_images[item.key].tag }}.tar |
| 110 | with_dict: "{{ kubeadm_images }}" |
| 111 | args: |
| 112 | chdir: "{{ containers_folder }}" |
| 113 | become: true |
| 114 | changed_when: false |
| 115 | |
| 116 | - name: Save misc container images |
| 117 | command: |- |
| 118 | docker save {{ downloads[item].repo }}:{{ downloads[item].tag }} |
| 119 | -o {{ downloads[item].repo }} -o {{ downloads[item].repo | replace('/', '_') }}_{{ downloads[item].tag }}.tar |
| 120 | loop: "{{ k8s_misc_images }}" |
| 121 | args: |
| 122 | chdir: "{{ containers_folder }}" |
| 123 | become: true |
| 124 | changed_when: false |
| 125 | |
| 126 | - name: Save other container images |
| 127 | command: |- |
| 128 | docker save {{ other_images[item.key].repo }}:{{ other_images[item.key].tag }} |
| 129 | -o {{ other_images[item.key].repo | replace('/', '_') }}_{{ other_images[item.key].tag }}.tar |
| 130 | with_dict: "{{ other_images }}" |
| 131 | args: |
| 132 | chdir: "{{ containers_folder }}" |
| 133 | become: true |
| 134 | changed_when: false |
| 135 | |
| 136 | # NOTE (fdegir): archive fails due to wrong permissions so we fix them |
| 137 | - name: Fix container image permissions |
| 138 | file: |
| 139 | path: "{{ containers_folder }}" |
| 140 | state: directory |
| 141 | recurse: true |
| 142 | mode: 0755 |
| 143 | become: true |
| 144 | |
| 145 | # vim: set ts=2 sw=2 expandtab: |