check_prerequisites.yml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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: Initialize variables
  16. set_fact:
  17. cobbler_container_status: false
  18. cobbler_image_status: false
  19. cobbler_config_status: false
  20. backup_map_status: false
  21. new_node_status: false
  22. provision_os_change: false
  23. previous_os: None
  24. tags: install
  25. - name: Set centos kickstart file name
  26. set_fact:
  27. cobbler_kickstart_file: "{{ cobbler_centos_ks }}"
  28. when: provision_os == os_supported_centos
  29. - name: Set rocky kickstart file name
  30. set_fact:
  31. cobbler_kickstart_file: "{{ cobbler_rocky_ks }}"
  32. when: provision_os == os_supported_rocky
  33. - name: Set rocky kickstart file name
  34. set_fact:
  35. cobbler_kickstart_file: "{{ cobbler_leap_ks }}"
  36. when: provision_os == os_supported_leap
  37. - name: Check if any backup file exists
  38. block:
  39. - name: Check status of backup file
  40. stat:
  41. path: "{{ role_path }}/files/backup_mapping_file.csv"
  42. register: backup_map
  43. - name: Set status for backup file
  44. set_fact:
  45. backup_map_status: true
  46. when: backup_map.stat.exists
  47. rescue:
  48. - name: Message
  49. debug:
  50. msg: "All nodes are new"
  51. verbosity: 2
  52. - name: Get K8s namespaces
  53. command: kubectl get namespaces
  54. changed_when: false
  55. register: k8s_namespaces
  56. - name: Create namespace network-config
  57. command: kubectl create namespace cobbler
  58. changed_when: true
  59. when: cobbler_namespace not in k8s_namespaces.stdout
  60. - name: Inspect the cobbler image
  61. command: buildah images
  62. register: cobbler_image_result
  63. failed_when: false
  64. changed_when: false
  65. tags: install
  66. - name: Check cobbler pod status on the machine
  67. command: kubectl get pods -n {{ cobbler_namespace }}
  68. register: cobbler_pod_result
  69. failed_when: false
  70. changed_when: false
  71. tags: install
  72. - name: Update cobbler image status
  73. set_fact:
  74. cobbler_image_status: true
  75. when: cobbler_image_name in cobbler_image_result.stdout
  76. tags: install
  77. - name: Update cobbler container status
  78. set_fact:
  79. cobbler_container_status: true
  80. when: "'cobbler' in cobbler_pod_result.stdout"
  81. tags: install
  82. - name: Get cobbler pod name
  83. command: 'kubectl get pod -n {{ cobbler_namespace }} -l app=cobbler -o jsonpath="{.items[0].metadata.name}"'
  84. changed_when: false
  85. register: cobbler_pod_name
  86. when: cobbler_container_status
  87. tags: install
  88. - name: Fetch cobbler profile list
  89. command: "kubectl exec --stdin --tty -n {{ cobbler_namespace }} {{ cobbler_pod_name.stdout }} -- cobbler profile list"
  90. changed_when: false
  91. register: cobbler_profile_list
  92. failed_when: false
  93. when: cobbler_container_status
  94. - name: Check crontab list
  95. command: "kubectl exec --stdin --tty -n {{ cobbler_namespace }} {{ cobbler_pod_name.stdout }} -- crontab -l"
  96. changed_when: false
  97. register: crontab_list
  98. failed_when: false
  99. when: cobbler_container_status
  100. - name: Check if .provisioned_os file exists
  101. stat:
  102. path: "/root/omnia/control_plane/roles/provision_cobbler/files/.provisioned_os"
  103. register: provisioned_os_file
  104. - name: Create .provisioned_os file
  105. file:
  106. path: "{{ role_path }}/files/.provisioned_os"
  107. state: touch
  108. mode: "{{ temp_file_perm }}"
  109. when: not provisioned_os_file.stat.exists
  110. - name: Check status of .provisioned_os file
  111. stat:
  112. path: "{{ role_path }}/files/.provisioned_os"
  113. register: provisioned_os_file
  114. - name: Get the previous os provisioned
  115. set_fact:
  116. previous_os: "{{ lookup('file', '{{ role_path }}/files/.provisioned_os').split() | last }}"
  117. when:
  118. - provisioned_os_file.stat.exists
  119. - provisioned_os_file.stat.size > 0
  120. - name: Update cobbler config status
  121. set_fact:
  122. cobbler_config_status: true
  123. when:
  124. - cobbler_container_status
  125. - (provision_os in cobbler_profile_list.stdout) or (previous_os in cobbler_profile_list.stdout) or ( "" in cobbler_profile_list.stdout)
  126. - "'* * * * * /usr/bin/ansible-playbook /root/tftp.yml' in crontab_list.stdout"
  127. - "'*/5 * * * * /usr/bin/ansible-playbook /root/inventory_creation.yml' in crontab_list.stdout"
  128. - name: Set status for provison_os_change
  129. set_fact:
  130. provision_os_change: true
  131. when:
  132. - previous_os != None
  133. - previous_os != provision_os
  134. - cobbler_config_status