create_pod.yml 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. # tasks file for sm pod creation
  16. - name: Get namespaces
  17. command: kubectl get namespaces
  18. changed_when: false
  19. register: k8s_namespaces
  20. tags: install
  21. - name: Ensure that namespace is created
  22. command: kubectl create namespace subnet-manager
  23. when: "'subnet-manager' not in k8s_namespaces.stdout"
  24. tags: install
  25. - name: Get K8s pods
  26. command: kubectl get pods --all-namespaces
  27. changed_when: false
  28. register: k8s_pods
  29. tags: install
  30. - name: Create subnet manager pod
  31. block:
  32. - name: Replace container name in sm config file
  33. replace:
  34. path: "{{ sm_kube_config_file }}"
  35. regexp: " containers:\n - name:.*"
  36. replace: " containers:\n - name: {{ sm_container_name }}"
  37. tags: install
  38. - name: Replace image name in sm config file
  39. replace:
  40. path: "{{ sm_kube_config_file }}"
  41. regexp: " image:.*"
  42. replace: " image: 'localhost/{{ sm_docker_image_name }}:{{ sm_docker_image_tag }}'"
  43. tags: install
  44. - name: Replace cache directory in sm config file
  45. replace:
  46. path: "{{ sm_kube_config_file }}"
  47. regexp: " - name: opensm-cache\n hostPath:\n path:.*"
  48. replace: " - name: opensm-cache\n hostPath:\n path: {{ subnet_manager.cache_directory }} "
  49. tags: install
  50. - name: Replace cache directory in sm config file
  51. replace:
  52. path: "{{ sm_kube_config_file }}"
  53. regexp: " - name: opensm-logs\n hostPath:\n path:.*"
  54. replace: " - name: opensm-logs\n hostPath:\n path: {{ subnet_manager.log_directory }} "
  55. tags: install
  56. - name: Create subnet manager pod
  57. command: "kubectl apply -f {{ sm_kube_config_file }}"
  58. tags: install
  59. when: "'subnet-manager' not in k8s_pods.stdout"