check_prerequisites.yml 3.1 KB

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