# 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: Turn Swap OFF (if not already disabled) command: /usr/sbin/swapoff -a tags: init - name: Initialize kubeadm command: /bin/kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address={{ manager_ip }} #command: /bin/kubeadm init register: init_output tags: init - name: Setup Directory for Kubernetes environment for root file: path=/root/.kube state=directory tags: init - name: Copy Kubernetes Config for root #do this for other users too? copy: src: /etc/kubernetes/admin.conf dest: /root/.kube/config owner: root group: root mode: 0644 remote_src: yes tags: init - name: Cluster token shell: kubeadm token list | cut -d ' ' -f1 | sed -n '2p' register: K8S_TOKEN tags: init - name: CA Hash shell: openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //' 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: "{{ manager_ip }}" tags: init - name: debug: msg: "[Manager] K8S_TOKEN_HOLDER K8S token is {{ hostvars['K8S_TOKEN_HOLDER']['token'] }}" tags: init - name: debug: msg: "[Manager] K8S_TOKEN_HOLDER K8S Hash is {{ hostvars['K8S_TOKEN_HOLDER']['hash'] }}" tags: init - name: debug: msg: "[Manager] K8S_MANAGER_IP is {{ manager_ip }}" tags: init - name: Setup Calico SDN network shell: kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml tags: init #- name: Setup Flannel SDN network #shell: kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml #tags: init - name: Create yaml repo for setup file: path: /root/k8s owner: root group: root mode: 0755 state: directory tags: init - name: Create Service Account (K8S Dashboard) Files copy: src=create_admin_user.yaml dest=/root/k8s/create_admin_user.yaml owner=root group=root mode=655 tags: init - name: Create Service Account (K8S Dashboard) - Create shell: kubectl create -f /root/k8s/create_admin_user.yaml tags: init - name: Create ClusterRoleBinding (K8S Dashboard) Files copy: src=create_clusterRoleBinding.yaml dest=/root/k8s/create_clusterRoleBinding.yaml owner=root group=root mode=655 tags: init - name: Create ClusterRoleBinding (K8S Dashboard) - Apply shell: kubectl create -f /root/k8s/create_clusterRoleBinding.yaml tags: init - name: Dump Bearer Token for K8S Dashboard Login shell: kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}') > /root/k8s/token tags: init - name: Edge / Workstation Install allows pods to scheudle on manager shell: kubectl taint nodes --all node-role.kubernetes.io/master- when: single_node tags: init # If more debug information is needed during init uncomment the following 2 lines #- debug: var=init_output.stdout_lines #tags: init