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
23 Oct 2023 16:02:14 +0000 00:22:08.95 nyctea root Ansible 2.15.2 ara 1.6.1 (client), 1.6.1 (server) Python 3.11.4 6 6 874 874 53 1

File: /root/.ansible/collections/ansible_collections/kubeinit/kubeinit/roles/kubeinit_rke/tasks/main.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: Deploy the cluster nodes
  ansible.builtin.include_role:
    name: kubeinit.kubeinit.kubeinit_libvirt
    tasks_from: deploy_ubuntu_guest.yml
    public: yes
  loop: "{{ groups['all_cluster_nodes'] }}"
  loop_control:
    loop_var: cluster_node
  vars:
    kubeinit_deployment_node_name: "{{ cluster_node }}"
    kubeinit_deployment_delegate: "{{ hostvars[cluster_node].target }}"
  when: kubeinit_cluster_nodes_deployed is not defined or not kubeinit_cluster_nodes_deployed

- name: Enable insecure registry in Docker
  ansible.builtin.shell: |
    # This is mandatory so the cluster nodes can fetch the
    # images from the local (insecure) registry
    sed -i '/^ExecStart=/ s/$/ --insecure-registry {{ kubeinit_registry_uri }}/' /lib/systemd/system/docker.service
    systemctl daemon-reload
    systemctl restart docker
  args:
    executable: /bin/bash
  register: _result
  changed_when: "_result.rc == 0"
  loop: "{{ groups['all_cluster_nodes'] }}"
  loop_control:
    loop_var: cluster_node
  delegate_to: "{{ cluster_node }}"
  when: "'registry' in kubeinit_cluster_hostvars.services"

- name: "Install RKE"
  ansible.builtin.shell: |
    ~/rke --version
    ~/rke up --ignore-docker-version -disable-port-check
  args:
    executable: /bin/bash
  register: _result
  changed_when: "_result.rc == 0"
  delegate_to: "{{ kubeinit_provision_service_node }}"

- name: Autoload kubeconfig
  ansible.builtin.shell: |
    echo "export KUBECONFIG=~/kube_config_cluster.yml" >> ~/.bashrc
  args:
    executable: /bin/bash
  ignore_errors: yes
  register: _result
  changed_when: "_result.rc == 0"
  delegate_to: "{{ kubeinit_provision_service_node }}"

- name: Create kube directory
  ansible.builtin.file:
    path: ~/.kube
    state: directory
    mode: '0644'
  delegate_to: "{{ kubeinit_provision_service_node }}"

- name: Copy the kubeconfig
  ansible.builtin.shell: |
    cp ~/kube_config_cluster.yml ~/.kube/config
  args:
    executable: /bin/bash
  register: _result
  changed_when: "_result.rc == 0"
  delegate_to: "{{ kubeinit_provision_service_node }}"

- name: Touch a file
  ansible.builtin.command: |
    touch ~/.kube/config
  register: _result
  changed_when: "_result.rc == 0"
  delegate_to: "{{ kubeinit_provision_service_node }}"

- name: Install kustomize
  ansible.builtin.shell: |
    curl -sL https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv5.1.0/kustomize_v5.1.0_linux_amd64.tar.gz > kustomize.tar.gz
    tar xzf ./kustomize.tar.gz
    mv ./kustomize /bin/
  args:
    executable: /bin/bash
  register: _result
  changed_when: "_result.rc == 0"
  delegate_to: "{{ kubeinit_provision_service_node }}"

- name: Allow schedule workloads in controller nodes if there are no compute nodes
  ansible.builtin.shell: |
    set -o pipefail
    for node in $(kubectl get nodes -o json | jq -r '.items[] | select(.spec.taints[]?.key=="node-role.kubernetes.io/controlplane") | .metadata.labels."kubernetes.io/hostname"');
    do
      kubectl taint node ${node} node-role.kubernetes.io/controlplane:NoSchedule-
      kubectl taint node ${node} node-role.kubernetes.io/etcd:NoExecute-
    done
  args:
    executable: /bin/bash
  register: _result
  changed_when: "_result.rc == 0"
  when: not kubeinit_compute_count|int > 0
  vars:
    kubeinit_deployment_node_name: "{{ kubeinit_provision_service_node }}"
  delegate_to: "{{ kubeinit_deployment_node_name }}"