k8s_services.yml 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. # Copyright 2021 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: Wait for CoreDNS to restart
  16. command: kubectl rollout status deployment/coredns -n kube-system
  17. changed_when: false
  18. failed_when: false
  19. - name: Get K8s pods
  20. command: kubectl get pods --all-namespaces
  21. changed_when: false
  22. register: k8s_pods
  23. - name: Deploy MetalLB
  24. command: "kubectl apply -f '{{ metallb_yaml_url }}'"
  25. changed_when: true
  26. when: "'metallb' not in k8s_pods.stdout"
  27. - name: Create MetalLB Setup Config Files
  28. copy:
  29. src: metal-config.yaml
  30. dest: "{{ metallb_config_file_dest }}"
  31. owner: root
  32. group: root
  33. mode: "{{ metallb_config_file_mode }}"
  34. - name: Replace metallb_addresses
  35. replace:
  36. path: "{{ metallb_config_file_dest }}"
  37. regexp: 'addresses:'
  38. replace: "{{ metallb_addresses }}"
  39. - name: Remove ^M characters from metal-config file
  40. shell: 'sed -e "s/\r//g" {{ metallb_config_file_dest }} > {{ metallb_config_updated_file_dest }}'
  41. args:
  42. warn: false
  43. changed_when: true
  44. - name: Update metal-config file permissions
  45. file:
  46. path: "{{ metallb_config_updated_file_dest }}"
  47. owner: root
  48. group: root
  49. mode: "{{ metallb_config_file_mode }}"
  50. - name: Remove old metallb-config file
  51. file:
  52. path: "{{ metallb_config_file_dest }}"
  53. state: absent
  54. - name: Create MetalLB Setup Deployment Files
  55. copy:
  56. src: metallb.yaml
  57. dest: "{{ metallb_deployment_file_dest }}"
  58. owner: root
  59. group: root
  60. mode: "{{ metallb_deployment_file_mode }}"
  61. - name: Replace metallb_container_port
  62. replace:
  63. path: "{{ metallb_deployment_file_dest }}"
  64. regexp: 'metallb_container_port'
  65. replace: "{{ metallb_container_port }}"
  66. - name: Replace metallb_container_port
  67. replace:
  68. path: "{{ metallb_deployment_file_dest }}"
  69. regexp: 'metallb_run_as_user_port'
  70. replace: "{{ metallb_run_as_user_port }}"
  71. - name: Deploy MetalLB
  72. command: "kubectl apply -f '{{ metallb_deployment_file_dest }}'"
  73. changed_when: true
  74. when: "'metallb' not in k8s_pods.stdout"
  75. - name: Create default setup for MetalLB
  76. command: "kubectl apply -f '{{ metallb_config_updated_file_dest }}'"
  77. changed_when: true
  78. when: "'metallb' not in k8s_pods.stdout"
  79. - name: Deploy K8s dashboard
  80. command: "kubectl apply -f {{ k8s_dashboard_yaml_url }}"
  81. changed_when: true
  82. when: "'kubernetes-dashboard' not in k8s_pods.stdout"
  83. - name: Copy k8s_dashboard_admin.yml file
  84. copy:
  85. src: k8s_dashboard_admin.yaml
  86. dest: "{{ k8s_dashboard_admin_file_dest }}"
  87. owner: root
  88. group: root
  89. mode: "{{ k8s_dashboard_admin_file_mode }}"
  90. - name: Create admin user for K8s dashboard
  91. command: "kubectl apply -f {{ k8s_dashboard_admin_file_dest }}"
  92. changed_when: true
  93. - name: Start NFS Client Provisioner
  94. command: "helm install stable/nfs-client-provisioner --set nfs.server='{{ ansible_default_ipv4.address }}' --set nfs.path='{{ nfs_path }}' --generate-name"
  95. changed_when: true
  96. when: "'nfs-client-provisioner' not in k8s_pods.stdout"
  97. - name: Set NFS-Client Provisioner as DEFAULT StorageClass
  98. shell: >
  99. kubectl patch storageclasses.storage.k8s.io nfs-client \
  100. -p '{ "metadata": { "annotations":{ "storageclass.kubernetes.io/is-default-class":"true" }}}'
  101. changed_when: true
  102. - name: Get K8s namespaces
  103. command: kubectl get namespaces
  104. changed_when: false
  105. register: k8s_namespaces
  106. - name: Create namespace network-config
  107. command: kubectl create namespace network-config
  108. changed_when: true
  109. when: "'network-config' not in k8s_namespaces.stdout"