main.yml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. # Copyright 2020 Dell Inc. or its subsidiaries. All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. ---
  15. - name: Turn Swap OFF (if not already disabled)
  16. command: /usr/sbin/swapoff -a
  17. tags: init
  18. - name: Initialize kubeadm
  19. command: /bin/kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address={{ manager_ip }}
  20. #command: /bin/kubeadm init
  21. register: init_output
  22. tags: init
  23. - name: Setup Directory for Kubernetes environment for root
  24. file: path=/root/.kube state=directory
  25. tags: init
  26. - name: Copy Kubernetes Config for root #do this for other users too?
  27. copy:
  28. src: /etc/kubernetes/admin.conf
  29. dest: /root/.kube/config
  30. owner: root
  31. group: root
  32. mode: 0644
  33. remote_src: yes
  34. tags: init
  35. - name: Cluster token
  36. shell: kubeadm token list | cut -d ' ' -f1 | sed -n '2p'
  37. register: K8S_TOKEN
  38. tags: init
  39. - name: CA Hash
  40. shell: openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'
  41. register: K8S_MANAGER_CA_HASH
  42. tags: init
  43. - name: Add K8S Manager IP, Token, and Hash to dummy host
  44. add_host:
  45. name: "K8S_TOKEN_HOLDER"
  46. token: "{{ K8S_TOKEN.stdout }}"
  47. hash: "{{ K8S_MANAGER_CA_HASH.stdout }}"
  48. ip: "{{ manager_ip }}"
  49. tags: init
  50. - name:
  51. debug:
  52. msg: "[Manager] K8S_TOKEN_HOLDER K8S token is {{ hostvars['K8S_TOKEN_HOLDER']['token'] }}"
  53. tags: init
  54. - name:
  55. debug:
  56. msg: "[Manager] K8S_TOKEN_HOLDER K8S Hash is {{ hostvars['K8S_TOKEN_HOLDER']['hash'] }}"
  57. tags: init
  58. - name:
  59. debug:
  60. msg: "[Manager] K8S_MANAGER_IP is {{ manager_ip }}"
  61. tags: init
  62. - name: Setup Calico SDN network
  63. shell: kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
  64. tags: init
  65. #- name: Setup Flannel SDN network
  66. #shell: kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
  67. #tags: init
  68. - name: Enabled GPU support in Kubernetes
  69. shell: kubectl create -f https://raw.githubusercontent.com/NVIDIA/k8s-device-plugin/1.0.0-beta4/nvidia-device-plugin.yml
  70. #https://raw.githubusercontent.com/NVIDIA/k8s-device-plugin/v1.11/nvidia-device-plugin.yml
  71. register: gpu_enable
  72. tags: init
  73. - name: Deploy Xilinx Device Plugin
  74. shell: kubectl create -f https://raw.githubusercontent.com/Xilinx/FPGA_as_a_Service/master/k8s-fpga-device-plugin/fpga-device-plugin.yml
  75. register: fpga_enable
  76. tags: init
  77. - name: Create yaml repo for setup
  78. file:
  79. path: /root/k8s
  80. owner: root
  81. group: root
  82. mode: 0755
  83. state: directory
  84. tags: init
  85. - name: Create Service Account (K8S Dashboard) Files
  86. copy: src=create_admin_user.yaml dest=/root/k8s/create_admin_user.yaml owner=root group=root mode=655
  87. tags: init
  88. - name: Create Service Account (K8S Dashboard) - Create
  89. shell: kubectl create -f /root/k8s/create_admin_user.yaml
  90. tags: init
  91. - name: Create ClusterRoleBinding (K8S Dashboard) Files
  92. copy: src=create_clusterRoleBinding.yaml dest=/root/k8s/create_clusterRoleBinding.yaml owner=root group=root mode=655
  93. tags: init
  94. - name: Create ClusterRoleBinding (K8S Dashboard) - Apply
  95. shell: kubectl create -f /root/k8s/create_clusterRoleBinding.yaml
  96. tags: init
  97. - name: Dump Bearer Token for K8S Dashboard Login
  98. shell: kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}') > /root/k8s/token
  99. tags: init
  100. - name: Edge / Workstation Install allows pods to scheudle on manager
  101. shell: kubectl taint nodes --all node-role.kubernetes.io/master-
  102. when: single_node
  103. tags: init
  104. # If more debug information is needed during init uncomment the following 2 lines
  105. #- debug: var=init_output.stdout_lines
  106. #tags: init