check_prerequisites.yml 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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: 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. tags: install
  23. - name: Set centos kickstart file name
  24. set_fact:
  25. cobbler_kickstart_file: "{{ cobbler_centos_ks }}"
  26. when: provision_os == os_supported_centos
  27. - name: Set rocky kickstart file name
  28. set_fact:
  29. cobbler_kickstart_file: "{{ cobbler_rocky_ks }}"
  30. when: provision_os == os_supported_rocky
  31. - name: Check if any backup file exists
  32. block:
  33. - name: Check status of backup file
  34. stat:
  35. path: "{{ role_path }}/files/backup_mapping_file.csv"
  36. register: backup_map
  37. - name: Set status for backup file
  38. set_fact:
  39. backup_map_status: true
  40. when: backup_map.stat.exists
  41. rescue:
  42. - name: Message
  43. debug:
  44. msg: "All nodes are new"
  45. verbosity: 2
  46. - name: Get K8s namespaces
  47. command: kubectl get namespaces
  48. changed_when: false
  49. register: k8s_namespaces
  50. - name: Create namespace network-config
  51. command: kubectl create namespace cobbler
  52. changed_when: true
  53. when: cobbler_namespace not in k8s_namespaces.stdout
  54. - name: Inspect the cobbler image
  55. command: buildah images
  56. register: cobbler_image_result
  57. failed_when: false
  58. changed_when: false
  59. tags: install
  60. - name: Check cobbler pod status on the machine
  61. command: kubectl get pods -n {{ cobbler_namespace }}
  62. register: cobbler_pod_result
  63. failed_when: false
  64. changed_when: false
  65. tags: install
  66. - name: Update cobbler image status
  67. set_fact:
  68. cobbler_image_status: true
  69. when: cobbler_image_name in cobbler_image_result.stdout
  70. tags: install
  71. - name: Update cobbler container status
  72. set_fact:
  73. cobbler_container_status: true
  74. when: "'cobbler' in cobbler_pod_result.stdout"
  75. tags: install
  76. - name: Get cobbler pod name
  77. command: 'kubectl get pod -n {{ cobbler_namespace }} -l app=cobbler -o jsonpath="{.items[0].metadata.name}"'
  78. changed_when: false
  79. register: cobbler_pod_name
  80. when: cobbler_container_status
  81. tags: install
  82. - name: Fetch cobbler profile list
  83. command: "kubectl exec --stdin --tty -n {{ cobbler_namespace }} {{ cobbler_pod_name.stdout }} -- cobbler profile list"
  84. changed_when: false
  85. register: cobbler_profile_list
  86. failed_when: false
  87. when: cobbler_container_status
  88. - name: Check crontab list
  89. command: "kubectl exec --stdin --tty -n {{ cobbler_namespace }} {{ cobbler_pod_name.stdout }} -- crontab -l"
  90. changed_when: false
  91. register: crontab_list
  92. failed_when: false
  93. when: cobbler_container_status
  94. - name: Update cobbler config status
  95. set_fact:
  96. cobbler_config_status: true
  97. when:
  98. - cobbler_container_status
  99. - provision_os in cobbler_profile_list.stdout
  100. - "'* * * * * /usr/bin/ansible-playbook /root/tftp.yml' in crontab_list.stdout"
  101. - "'*/5 * * * * /usr/bin/ansible-playbook /root/inventory_creation.yml' in crontab_list.stdout"