# Copyright 2020 Dell Inc. or its subsidiaries. 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: Disable swap command: /usr/sbin/swapoff -a changed_when: true tags: init - name: Get netaddr setup: filter: ansible_default_ipv4.address - name: Get K8s nodes status command: kubectl get nodes changed_when: false ignore_errors: True register: k8s_nodes tags: init - name: Get K8s ready compute nodes shell: kubectl get node --selector='!node-role.kubernetes.io/master' | grep -v 'NotReady' changed_when: false ignore_errors: True register: k8s_nodes_ready tags: init - name: Get K8s not ready compute nodes shell: kubectl get node --selector='!node-role.kubernetes.io/master' | grep 'NotReady' changed_when: false ignore_errors: True register: k8s_nodes_not_ready tags: init - name: Initialize kubeadm command: "/bin/kubeadm init --pod-network-cidr='{{ hostvars['127.0.0.1']['k8s_pod_network_cidr'] }}' \ --apiserver-advertise-address='{{ ansible_default_ipv4.address }}'" changed_when: true when: "'master' not in k8s_nodes.stdout" register: init_output tags: init - name: Setup directory for Kubernetes environment for root file: path: "{{ k8s_root_directory }}" state: directory mode: "{{ k8s_root_directory_mode }}" tags: init - name: Copy Kubernetes config for root copy: src: "{{ k8s_config_src }}" dest: "{{ k8s_config_dest }}" owner: root group: root mode: "{{ k8s_config_file_mode }}" remote_src: yes tags: init - name: Update the kubernetes config file permissions shell: "chown $(id -u):$(id -g) '{{ k8s_config_dest }}'" args: warn: false changed_when: true tags: init - name: Cluster token shell: > set -o pipefail && \ kubeadm token list | cut -d ' ' -f1 | sed -n '2p' changed_when: false register: K8S_TOKEN tags: init - name: CA Hash shell: > set -o pipefail && \ openssl x509 -pubkey -in {{ k8s_cert_path }} | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //' changed_when: false register: K8S_MANAGER_CA_HASH tags: init - name: Add K8S Manager IP, Token, and Hash to dummy host add_host: name: "K8S_TOKEN_HOLDER" token: "{{ K8S_TOKEN.stdout }}" hash: "{{ K8S_MANAGER_CA_HASH.stdout }}" ip: "{{ ansible_default_ipv4.address }}" k8s_nodes: "{{ k8s_nodes.stdout }}" k8s_nodes_ready: "{{ k8s_nodes_ready.stdout }}" k8s_nodes_not_ready: "{{ k8s_nodes_not_ready.stdout }}" tags: init - name: Print k8s token debug: msg: "[Manager] K8S_TOKEN_HOLDER K8S token is {{ hostvars['K8S_TOKEN_HOLDER']['token'] }}" verbosity: 2 tags: init - name: Print k8s hash debug: msg: "[Manager] K8S_TOKEN_HOLDER K8S Hash is {{ hostvars['K8S_TOKEN_HOLDER']['hash'] }}" verbosity: 2 tags: init - name: Print k8s ansible_default_ipv4.address debug: msg: "[Manager] K8S_MANAGER_IP is {{ ansible_default_ipv4.address }}" verbosity: 2 tags: init - name: Setup Calico SDN network command: "kubectl apply -f '{{ calico_yml_url }}'" when: hostvars['127.0.0.1']['k8s_cni'] == "calico" tags: init - name: Setup Flannel SDN network command: "kubectl apply -f '{{ flannel_yml_url }}'" when: hostvars['127.0.0.1']['k8s_cni'] == "flannel" tags: init - name: Create yaml repo for setup file: path: "{{ yaml_repo_dir_path }}" state: directory mode: "{{ yaml_repo_dir_mode }}" tags: init - name: Create service account (K8s dashboard) files copy: src: create_admin_user.yaml dest: "{{ k8s_service_account_file_dest }}" owner: root group: root mode: "{{ k8s_service_account_file_mode }}" tags: init - name: Check K8s service accounts status command: "kubectl get serviceaccounts" changed_when: false register: k8s_service_accounts tags: init - name: Create service account (K8s dashboard) command: "kubectl create -f '{{ k8s_service_account_file_dest }}'" changed_when: true when: "'default' not in k8s_service_accounts.stdout" tags: init - name: Create clusterRoleBinding (K8s dashboard) files copy: src: create_clusterRoleBinding.yaml dest: "{{ k8s_clusterRoleBinding_file_dest }}" owner: root group: root mode: "{{ k8s_clusterRoleBinding_file_mode }}" tags: init - name: Create clusterRoleBinding (K8s dashboard) command: "kubectl create -f '{{ k8s_clusterRoleBinding_file_dest }}'" changed_when: true ignore_errors: True tags: init - name: Dump bearer token for K8s dashboard login shell: > set -o pipefail && \ kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}') > /root/k8s/token changed_when: true tags: init - name: Edge / Workstation Install allows pods to scheudle on manager command: kubectl taint nodes --all node-role.kubernetes.io/master- when: groups['manager'][0] == groups['compute'][0] and groups['compute']|length == 1 tags: init