startup_omnia.yml 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 mnt 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: Unmount tmp directory
  71. command: "umount {{ mount_dir }}"
  72. changed_when: true
  73. failed_when: false
  74. - name: Delete tmp directory
  75. file:
  76. path: "{{ mount_dir }}"
  77. state: absent
  78. - block:
  79. - name: Fetch SElinux mode
  80. command: /usr/sbin/sestatus
  81. register: sestatus_current
  82. changed_when: false
  83. - name: Set SElinux to permissive mode
  84. command: /usr/sbin/setenforce 0
  85. changed_when: true
  86. when: '"SELinux status: enabled" in sestatus_current.stdout_lines'
  87. when: os_supported_leap not in ansible_distribution | lower
  88. - name: Disable SWAP
  89. command: /usr/sbin/swapoff -a
  90. changed_when: true
  91. - name: Start and enable kubernetes - kubelet
  92. service:
  93. name: kubelet
  94. state: restarted
  95. enabled: yes
  96. - name: Wait for 3 minutes
  97. pause:
  98. minutes: "{{ wait_time_minutes }}"
  99. - name: Get K8s nodes status
  100. command: kubectl get nodes
  101. changed_when: false
  102. register: k8s_nodes
  103. retries: "{{ max_retries }}"
  104. until: "'master' in k8s_nodes.stdout"
  105. - block:
  106. - name: Check mngmnt_network pod status
  107. command: kubectl get pods -n {{ management_network_namespace }}
  108. changed_when: false
  109. register: mngmnt_network_pod_status
  110. failed_when: false
  111. - name: Wait for mngmnt_network pod to come to ready state
  112. command: kubectl wait --for=condition=ready -n {{ management_network_namespace }} pod -l app=mngmnt-network
  113. changed_when: false
  114. when: management_network_pod in mngmnt_network_pod_status.stdout
  115. - name: Get mngmnt_network pod name
  116. command: 'kubectl get pod -n {{ management_network_namespace }} -l app=mngmnt-network -o jsonpath="{.items[0].metadata.name}"'
  117. changed_when: false
  118. register: mngmnt_network_pod_name
  119. when: management_network_pod in mngmnt_network_pod_status.stdout
  120. - name: Configuring mngmnt_network container
  121. command: 'kubectl exec --stdin --tty -n {{ management_network_namespace }} {{ mngmnt_network_pod_name.stdout }} \
  122. -- ansible-playbook /root/mngmnt_container_configure.yml -e mngmnt_nic="{{ mngmnt_network_nic }}"'
  123. changed_when: false
  124. failed_when: false
  125. when: management_network_pod in mngmnt_network_pod_status.stdout
  126. when: device_config_support
  127. - name: Check cobbler pod status
  128. command: kubectl get pods -n {{ cobbler_namespace }}
  129. changed_when: false
  130. register: cobbler_pod_status
  131. failed_when: false
  132. - name: Wait for cobbler pod to come to ready state
  133. command: kubectl wait --for=condition=ready -n {{ cobbler_namespace }} pod -l app=cobbler
  134. changed_when: false
  135. when: cobbler_pod in cobbler_pod_status.stdout
  136. - name: Get cobbler pod name
  137. command: 'kubectl get pod -n {{ cobbler_namespace }} -l app=cobbler -o jsonpath="{.items[0].metadata.name}"'
  138. changed_when: false
  139. register: cobbler_pod_name
  140. when: cobbler_pod in cobbler_pod_status.stdout
  141. - name: Configuring cobbler inside container (It may take 5-10 mins)
  142. 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 }}"
  143. changed_when: true
  144. when: cobbler_pod in cobbler_pod_status.stdout