main.yml 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. ---
  2. - name: Turn Swap OFF (if not already disabled)
  3. command: /usr/sbin/swapoff -a
  4. tags: init
  5. - name: Initialize kubeadm
  6. command: /bin/kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=10.0.0.1
  7. #command: /bin/kubeadm init
  8. register: init_output
  9. tags: init
  10. - name: Setup Directory for Kubernetes environment for root
  11. file: path=/root/.kube state=directory
  12. tags: init
  13. - name: Copy Kubernetes Config for root #do this for other users too?
  14. copy: src=/etc/kubernetes/admin.conf dest=/root/.kube/config owner=root group=root mode=644
  15. tags: init
  16. - name: Cluster token
  17. shell: kubeadm token list | cut -d ' ' -f1 | sed -n '2p'
  18. register: K8S_TOKEN
  19. tags: init
  20. - name: CA Hash
  21. shell: openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'
  22. register: K8S_MASTER_CA_HASH
  23. tags: init
  24. - name: Add K8S Master IP, Token, and Hash to dummy host
  25. add_host:
  26. name: "K8S_TOKEN_HOLDER"
  27. token: "{{ K8S_TOKEN.stdout }}"
  28. hash: "{{ K8S_MASTER_CA_HASH.stdout }}"
  29. #ip: "{{ ansible_ib0.ipv4.address }}"
  30. ip: "{{ ansible_p3p1.ipv4.address }}"
  31. tags: init
  32. - name:
  33. debug:
  34. msg: "[Master] K8S_TOKEN_HOLDER K8S token is {{ hostvars['K8S_TOKEN_HOLDER']['token'] }}"
  35. tags: init
  36. - name:
  37. debug:
  38. msg: "[Master] K8S_TOKEN_HOLDER K8S Hash is {{ hostvars['K8S_TOKEN_HOLDER']['hash'] }}"
  39. tags: init
  40. - name:
  41. debug:
  42. msg: "[Master] K8S_MASTER_IP is {{ hostvars['K8S_TOKEN_HOLDER']['ip'] }}"
  43. tags: init
  44. - name: Setup Flannel SDN network
  45. shell: kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
  46. tags: init
  47. - name: Enabled GPU support in Kubernetes
  48. #script: enable_gpu_k8s.sh
  49. shell: kubectl create -f https://raw.githubusercontent.com/NVIDIA/k8s-device-plugin/1.0.0-beta4/nvidia-device-plugin.yml
  50. #https://raw.githubusercontent.com/NVIDIA/k8s-device-plugin/v1.11/nvidia-device-plugin.yml
  51. register: gpu_enable
  52. tags: init
  53. - name: Create yaml repo for setup
  54. file:
  55. path: /root/k8s
  56. state: directory
  57. tags: init
  58. - name: Create Service Account (K8S Dashboard) Files
  59. copy: src=create_admin_user.yaml dest=/root/k8s/create_admin_user.yaml owner=root group=root mode=655
  60. tags: init
  61. - name: Create Service Account (K8S Dashboard) - Create
  62. shell: kubectl create -f /root/k8s/create_admin_user.yaml
  63. tags: init
  64. - name: Create ClusterRoleBinding (K8S Dashboard) Files
  65. copy: src=create_clusterRoleBinding.yaml dest=/root/k8s/create_clusterRoleBinding.yaml owner=root group=root mode=655
  66. tags: init
  67. - name: Create ClusterRoleBinding (K8S Dashboard) - Apply
  68. shell: kubectl create -f /root/k8s/create_clusterRoleBinding.yaml
  69. tags: init
  70. - name: Dump Bearer Token for K8S Dashboard Login
  71. shell: kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}') > /root/k8s/token
  72. tags: init
  73. # If more debug information is needed during init uncomment the following 2 lines
  74. #- debug: var=init_output.stdout_lines
  75. #tags: init