main.yml 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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:
  15. src: /etc/kubernetes/admin.conf
  16. dest: /root/.kube/config
  17. owner: root
  18. group: root
  19. mode: 644
  20. remote_src: yes
  21. tags: init
  22. - name: Cluster token
  23. shell: kubeadm token list | cut -d ' ' -f1 | sed -n '2p'
  24. register: K8S_TOKEN
  25. tags: init
  26. - name: CA Hash
  27. shell: openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'
  28. register: K8S_MASTER_CA_HASH
  29. tags: init
  30. - name: Add K8S Master IP, Token, and Hash to dummy host
  31. add_host:
  32. name: "K8S_TOKEN_HOLDER"
  33. token: "{{ K8S_TOKEN.stdout }}"
  34. hash: "{{ K8S_MASTER_CA_HASH.stdout }}"
  35. #ip: "{{ ansible_ib0.ipv4.address }}"
  36. ip: "{{ ansible_p3p1.ipv4.address }}"
  37. tags: init
  38. - name:
  39. debug:
  40. msg: "[Master] K8S_TOKEN_HOLDER K8S token is {{ hostvars['K8S_TOKEN_HOLDER']['token'] }}"
  41. tags: init
  42. - name:
  43. debug:
  44. msg: "[Master] K8S_TOKEN_HOLDER K8S Hash is {{ hostvars['K8S_TOKEN_HOLDER']['hash'] }}"
  45. tags: init
  46. - name:
  47. debug:
  48. msg: "[Master] K8S_MASTER_IP is {{ hostvars['K8S_TOKEN_HOLDER']['ip'] }}"
  49. tags: init
  50. - name: Setup Calico SDN network
  51. shell: kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
  52. tags: init
  53. #- name: Setup Flannel SDN network
  54. #shell: kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
  55. #tags: init
  56. - name: Enabled GPU support in Kubernetes
  57. shell: kubectl create -f https://raw.githubusercontent.com/NVIDIA/k8s-device-plugin/1.0.0-beta4/nvidia-device-plugin.yml
  58. #https://raw.githubusercontent.com/NVIDIA/k8s-device-plugin/v1.11/nvidia-device-plugin.yml
  59. register: gpu_enable
  60. tags: init
  61. - name: Create yaml repo for setup
  62. file:
  63. path: /root/k8s
  64. state: directory
  65. tags: init
  66. - name: Create Service Account (K8S Dashboard) Files
  67. copy: src=create_admin_user.yaml dest=/root/k8s/create_admin_user.yaml owner=root group=root mode=655
  68. tags: init
  69. - name: Create Service Account (K8S Dashboard) - Create
  70. shell: kubectl create -f /root/k8s/create_admin_user.yaml
  71. tags: init
  72. - name: Create ClusterRoleBinding (K8S Dashboard) Files
  73. copy: src=create_clusterRoleBinding.yaml dest=/root/k8s/create_clusterRoleBinding.yaml owner=root group=root mode=655
  74. tags: init
  75. - name: Create ClusterRoleBinding (K8S Dashboard) - Apply
  76. shell: kubectl create -f /root/k8s/create_clusterRoleBinding.yaml
  77. tags: init
  78. - name: Dump Bearer Token for K8S Dashboard Login
  79. shell: kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}') > /root/k8s/token
  80. tags: init
  81. # If more debug information is needed during init uncomment the following 2 lines
  82. #- debug: var=init_output.stdout_lines
  83. #tags: init