main.yml 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 Calico SDN network
  45. shell: kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
  46. tags: init
  47. #- name: Setup Flannel SDN network
  48. #shell: kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
  49. #tags: init
  50. - name: Enabled GPU support in Kubernetes
  51. shell: kubectl create -f https://raw.githubusercontent.com/NVIDIA/k8s-device-plugin/1.0.0-beta4/nvidia-device-plugin.yml
  52. #https://raw.githubusercontent.com/NVIDIA/k8s-device-plugin/v1.11/nvidia-device-plugin.yml
  53. register: gpu_enable
  54. tags: init
  55. - name: Create yaml repo for setup
  56. file:
  57. path: /root/k8s
  58. state: directory
  59. tags: init
  60. - name: Create Service Account (K8S Dashboard) Files
  61. copy: src=create_admin_user.yaml dest=/root/k8s/create_admin_user.yaml owner=root group=root mode=655
  62. tags: init
  63. - name: Create Service Account (K8S Dashboard) - Create
  64. shell: kubectl create -f /root/k8s/create_admin_user.yaml
  65. tags: init
  66. - name: Create ClusterRoleBinding (K8S Dashboard) Files
  67. copy: src=create_clusterRoleBinding.yaml dest=/root/k8s/create_clusterRoleBinding.yaml owner=root group=root mode=655
  68. tags: init
  69. - name: Create ClusterRoleBinding (K8S Dashboard) - Apply
  70. shell: kubectl create -f /root/k8s/create_clusterRoleBinding.yaml
  71. tags: init
  72. - name: Dump Bearer Token for K8S Dashboard Login
  73. shell: kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}') > /root/k8s/token
  74. tags: init
  75. # If more debug information is needed during init uncomment the following 2 lines
  76. #- debug: var=init_output.stdout_lines
  77. #tags: init