Playbook #1

/root/kubeinit/ci/builds/6mbKNrxD/0/kubeinit/kubeinit/kubeinit-aux/kubeinit/playbook.yml

Report Status CLI Date Duration Controller User Versions Hosts Plays Tasks Results Files Records
29 Oct 2023 16:01:56 +0000 00:38:07.95 nyctea root Ansible 2.15.2 ara 1.6.1 (client), 1.6.1 (server) Python 3.11.4 5 6 825 825 48 1

File: /root/.ansible/collections/ansible_collections/kubeinit/kubeinit/roles/kubeinit_libvirt/tasks/download_cloud_images.yml

---
# Copyright kubeinit contributors
# 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.

- name: Prepare the environment and stop if required
  block:
    - name: Prepare environment if not prepared
      ansible.builtin.include_role:
        name: kubeinit.kubeinit.kubeinit_prepare
        public: true
      vars:
        environment_prepared: "{{ 'kubeinit_facts' in groups }}"
      when: not environment_prepared

    - name: Stop the deployment if required
      block:
        - name: "Stop before 'task-download-images' when requested"
          ansible.builtin.add_host:
            name: "kubeinit-facts"
            playbook_terminated: true
        - name: End play
          ansible.builtin.meta: end_play
      when: kubeinit_stop_before_task is defined and kubeinit_stop_before_task == 'task-download-images'
  tags: omit_from_grapher

#
# Download distribution specific images
#
- name: Create tuples for hosts and guest vms
  ansible.builtin.set_fact:
    all_hosts_guest_vms: "{{ (all_hosts_guest_vms | default([])) + ([hypervisor] | product([guest_vm])) }}"
  loop: "{{ groups['all_hosts'] | product(groups['all_guest_vms']) }}"
  vars:
    hypervisor: "{{ item[0] }}"
    guest_vm: "{{ item[1] }}"
  when: hostvars[guest_vm].target in hypervisor

- name: Create new directories for config files per node
  ansible.builtin.file:
    path: "{{ kubeinit_libvirt_hypervisor_tmp_dir }}/{{ guest_vm }}"
    state: directory
    mode: 0775
    recurse: yes
  loop: "{{ all_hosts_guest_vms }}"
  vars:
    kubeinit_deployment_node_name: "{{ item[0] }}"
    guest_vm: "{{ hostvars[item[1]].guest_name }}"
  delegate_to: "{{ kubeinit_deployment_node_name }}"

- name: Create tuples for hosts and cloud images
  ansible.builtin.set_fact:
    all_hosts_cloud_images: "{{ (all_hosts_cloud_images | default([])) + ([hypervisor] | product([kubeinit_libvirt_cloud_images[kubeinit_cluster_distro]])) }}"
  loop: "{{ all_hosts_guest_vms }}"
  vars:
    hypervisor: "{{ item[0] }}"
  when: kubeinit_libvirt_cloud_images[kubeinit_cluster_distro] is defined

- name: Remove duplicates
  ansible.builtin.set_fact:
    all_hosts_cloud_images: "{{ (all_hosts_cloud_images | default([])) | unique }}"

- name: Download cloud images
  ansible.builtin.get_url:
    validate_certs: False
    use_proxy: True
    url: "{{ cloud_image.uri }}{{ cloud_image.image }}"
    dest: "{{ kubeinit_libvirt_target_image_dir }}/{{ cloud_image.image }}"
    force: no
    mode: '0666'
    owner: "{{ hostvars[kubeinit_deployment_node_name].libvirt_qemu_user }}"
  loop: "{{ all_hosts_cloud_images }}"
  vars:
    kubeinit_deployment_node_name: "{{ item[0] }}"
    cloud_image: "{{ item[1] }}"
  delegate_to: "{{ kubeinit_deployment_node_name }}"

#
# TODO:FIXME: Make sure the kernel update do not break the Guest from booting
#

- name: Update packages in cloud images
  ansible.builtin.command: |
    virt-customize -a {{ kubeinit_libvirt_target_image_dir }}/{{ cloud_image.image }} {% if (kubeinit_cluster_distro == 'cdk' or kubeinit_cluster_distro == 'rke') %}--run-command 'env DEBIAN_FRONTEND=noninteractive apt-get -y --allow-remove-essential purge shim-signed'{% endif %} --update
  loop: "{{ all_hosts_cloud_images }}"
  vars:
    kubeinit_deployment_node_name: "{{ item[0] }}"
    cloud_image: "{{ item[1] }}"
  register: _result
  changed_when: "_result.rc == 0"
  delegate_to: "{{ kubeinit_deployment_node_name }}"
  # This is dangerous,do not run packages upgrades with virt-customize
  when: false

#
# Download extra cloud images for Windows compute nodes or any miscelaneous image requirement
#

- name: Create tuples for hosts and extra cloud images
  ansible.builtin.set_fact:
    all_hosts_extra_cloud_images: "{{ (all_hosts_extra_cloud_images | default([])) + ([hypervisor] | product(kubeinit_libvirt_extra_cloud_images)) }}"
  loop: "{{ all_hosts_guest_vms }}"
  vars:
    hypervisor: "{{ item[0] }}"

- name: Download extra cloud images
  ansible.builtin.get_url:
    validate_certs: False
    use_proxy: True
    url: "{{ cloud_image.uri }}{{ cloud_image.image }}"
    dest: "{{ kubeinit_libvirt_target_image_dir }}/{{ cloud_image.image }}"
    force: no
    mode: '0666'
    owner: "{{ hostvars[kubeinit_deployment_node_name].libvirt_qemu_user }}"
  loop: "{{ all_hosts_extra_cloud_images }}"
  vars:
    kubeinit_deployment_node_name: "{{ item[0] }}"
    cloud_image: "{{ item[1] }}"
  delegate_to: "{{ kubeinit_deployment_node_name }}"


- name: Add hosts and stop if required
  block:
    - name: Add task-download-images to tasks_completed
      ansible.builtin.add_host:
        name: "kubeinit-facts"
        tasks_completed: "{{ kubeinit_facts_hostvars.tasks_completed | union(['task-download-images']) }}"

    - name: Update kubeinit_facts_hostvars
      ansible.builtin.set_fact:
        kubeinit_facts_hostvars: "{{ hostvars['kubeinit-facts'] }}"

    - name: Stop the deployment if required
      block:
        - name: Stop after 'task-download-images' when requested
          ansible.builtin.add_host:
            name: "kubeinit-facts"
            playbook_terminated: true
        - name: End play
          ansible.builtin.meta: end_play
      when: kubeinit_stop_after_task is defined and kubeinit_stop_after_task in kubeinit_facts_hostvars.tasks_completed
  tags: omit_from_grapher