startup_omnia.yml 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. # Copyright 2022 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: Start omnia services on reboot
  16. hosts: localhost
  17. connection: local
  18. vars:
  19. wait_time_minutes: 3
  20. os_supported_leap: "leap"
  21. src_resolv_conf: /tmp/resolv.conf
  22. dest_resolv_conf: /etc/resolv.conf
  23. max_retries: 20
  24. cobbler_namespace: cobbler
  25. cobbler_pod: cobbler
  26. cobbler_kickstart_file: rocky8.ks
  27. management_network_namespace: network-config
  28. management_network_pod: mngmnt-network-container
  29. file_perm: '0775'
  30. mount_dir: /mnt/temp/
  31. tasks:
  32. - name: Wait for 3 minutes
  33. pause:
  34. minutes: "{{ wait_time_minutes }}"
  35. - name: Include base_vars.yml
  36. include_vars: ../../../input_params/base_vars.yml
  37. - name: Check resolv.conf file is present
  38. stat:
  39. path: "{{ src_resolv_conf }}"
  40. register: resolv_conf_check
  41. - name: Copy resolv.conf file
  42. copy:
  43. src: "{{ src_resolv_conf }}"
  44. dest: "{{ dest_resolv_conf }}"
  45. mode: preserve
  46. when: resolv_conf_check.stat.exists
  47. - name: Check if mount iso file exists
  48. stat:
  49. path: "/mnt/{{ provision_os }}/EFI/BOOT/grub.cfg"
  50. register: mount_iso_check
  51. - name: Create tmp directory
  52. file:
  53. path: "{{ mount_dir }}"
  54. state: directory
  55. mode: "{{ file_perm }}"
  56. when: not mount_iso_check.stat.exists
  57. - name: Mount the iso file
  58. command: mount -o loop {{ iso_file_path }} {{ mount_dir }}
  59. changed_when: false
  60. failed_when: false
  61. args:
  62. warn: false
  63. when: not mount_iso_check.stat.exists
  64. - name: Copy files to tmp folder
  65. command: "rsync -AHPSXav {{ mount_dir }} /mnt/{{ provision_os }}"
  66. changed_when: true
  67. args:
  68. warn: false
  69. when: not mount_iso_check.stat.exists
  70. - name: Delete tmp directory
  71. file:
  72. path: "{{ mount_dir }}"
  73. state: absent
  74. when: not mount_iso_check.stat.exists
  75. - block:
  76. - name: Fetch SElinux mode
  77. command: /usr/sbin/sestatus
  78. register: sestatus_current
  79. changed_when: false
  80. - name: Set SElinux to permissive mode
  81. command: /usr/sbin/setenforce 0
  82. changed_when: true
  83. when: '"SELinux status: enabled" in sestatus_current.stdout_lines'
  84. when: os_supported_leap not in ansible_distribution | lower
  85. - name: Disable SWAP
  86. command: /usr/sbin/swapoff -a
  87. changed_when: true
  88. - name: Start and enable kubernetes - kubelet
  89. service:
  90. name: kubelet
  91. state: restarted
  92. enabled: yes
  93. - name: Wait for 3 minutes
  94. pause:
  95. minutes: "{{ wait_time_minutes }}"
  96. - name: Get K8s nodes status
  97. command: kubectl get nodes
  98. changed_when: false
  99. register: k8s_nodes
  100. retries: "{{ max_retries }}"
  101. until: "'master' in k8s_nodes.stdout"
  102. - block:
  103. - name: Check mngmnt_network pod status
  104. command: kubectl get pods -n {{ management_network_namespace }}
  105. changed_when: false
  106. register: mngmnt_network_pod_status
  107. failed_when: false
  108. - name: Wait for mngmnt_network pod to come to ready state
  109. command: kubectl wait --for=condition=ready -n {{ management_network_namespace }} pod -l app=mngmnt-network
  110. changed_when: false
  111. when: management_network_pod in mngmnt_network_pod_status.stdout
  112. - name: Get mngmnt_network pod name
  113. command: 'kubectl get pod -n {{ management_network_namespace }} -l app=mngmnt-network -o jsonpath="{.items[0].metadata.name}"'
  114. changed_when: false
  115. register: mngmnt_network_pod_name
  116. when: management_network_pod in mngmnt_network_pod_status.stdout
  117. - name: Configuring mngmnt_network container
  118. command: 'kubectl exec --stdin --tty -n {{ management_network_namespace }} {{ mngmnt_network_pod_name.stdout }} \
  119. -- ansible-playbook /root/mngmnt_container_configure.yml -e mngmnt_nic="{{ mngmnt_network_nic }}"'
  120. changed_when: false
  121. failed_when: false
  122. when: management_network_pod in mngmnt_network_pod_status.stdout
  123. when: device_config_support
  124. - name: Check cobbler pod status
  125. command: kubectl get pods -n {{ cobbler_namespace }}
  126. changed_when: false
  127. register: cobbler_pod_status
  128. failed_when: false
  129. - name: Wait for cobbler pod to come to ready state
  130. command: kubectl wait --for=condition=ready -n {{ cobbler_namespace }} pod -l app=cobbler
  131. changed_when: false
  132. when: cobbler_pod in cobbler_pod_status.stdout
  133. - name: Get cobbler pod name
  134. command: 'kubectl get pod -n {{ cobbler_namespace }} -l app=cobbler -o jsonpath="{.items[0].metadata.name}"'
  135. changed_when: false
  136. register: cobbler_pod_name
  137. when: cobbler_pod in cobbler_pod_status.stdout
  138. - name: Configuring cobbler inside container (It may take 5-10 mins)
  139. command: "kubectl exec --stdin --tty -n {{ cobbler_namespace }} {{ cobbler_pod_name.stdout }} -- ansible-playbook /root/cobbler_configurations_rocky.yml -e provision_os={{ provision_os }} -e file_perm={{ file_perm }}"
  140. changed_when: true
  141. when: cobbler_pod in cobbler_pod_status.stdout