main.yml 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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={{ master_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: 644
  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_MASTER_CA_HASH
  42. tags: init
  43. - name: Add K8S Master IP, Token, and Hash to dummy host
  44. add_host:
  45. name: "K8S_TOKEN_HOLDER"
  46. token: "{{ K8S_TOKEN.stdout }}"
  47. hash: "{{ K8S_MASTER_CA_HASH.stdout }}"
  48. ip: "{{ master_ip }}"
  49. tags: init
  50. - name:
  51. debug:
  52. msg: "[Master] K8S_TOKEN_HOLDER K8S token is {{ hostvars['K8S_TOKEN_HOLDER']['token'] }}"
  53. tags: init
  54. - name:
  55. debug:
  56. msg: "[Master] K8S_TOKEN_HOLDER K8S Hash is {{ hostvars['K8S_TOKEN_HOLDER']['hash'] }}"
  57. tags: init
  58. - name:
  59. debug:
  60. msg: "[Master] K8S_MASTER_IP is {{ master_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: Create yaml repo for setup
  74. file:
  75. path: /root/k8s
  76. state: directory
  77. tags: init
  78. - name: Create Service Account (K8S Dashboard) Files
  79. copy: src=create_admin_user.yaml dest=/root/k8s/create_admin_user.yaml owner=root group=root mode=655
  80. tags: init
  81. - name: Create Service Account (K8S Dashboard) - Create
  82. shell: kubectl create -f /root/k8s/create_admin_user.yaml
  83. tags: init
  84. - name: Create ClusterRoleBinding (K8S Dashboard) Files
  85. copy: src=create_clusterRoleBinding.yaml dest=/root/k8s/create_clusterRoleBinding.yaml owner=root group=root mode=655
  86. tags: init
  87. - name: Create ClusterRoleBinding (K8S Dashboard) - Apply
  88. shell: kubectl create -f /root/k8s/create_clusterRoleBinding.yaml
  89. tags: init
  90. - name: Dump Bearer Token for K8S Dashboard Login
  91. shell: kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}') > /root/k8s/token
  92. tags: init
  93. - name: Edge / Workstation Install allows pods to scheudle on master
  94. shell: kubectl taint nodes --all node-role.kubernetes.io/master-
  95. when: single_node
  96. tags: init
  97. # If more debug information is needed during init uncomment the following 2 lines
  98. #- debug: var=init_output.stdout_lines
  99. #tags: init