mapping_file.yml 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. # limitations under the License.
  13. ---
  14. - name: Remove blank lines
  15. shell: set -o pipefail && awk -F, 'length>NF+1' {{ host_mapping_file_path }} > {{ temp_host_mapping_file }}
  16. changed_when: false
  17. tags: install
  18. - name: Remove blank spaces
  19. shell: set -o pipefail && sed -i.bak -E 's/(^|,)[[:blank:]]+/\1/g; s/[[:blank:]]+(,|$)/\1/g' {{ temp_host_mapping_file }}
  20. args:
  21. warn: no
  22. changed_when: false
  23. tags: install
  24. - name: Compare the file for new nodes
  25. block:
  26. - name: Check difference
  27. shell: set -o pipefail && diff {{ temp_host_mapping_file }} {{ role_path }}/files/backup_host_mapping_file.csv| tr -d \>|tr -d \<| grep -E -- ', & :| '
  28. register: diff_output
  29. changed_when: false
  30. failed_when: false
  31. - name: Status of new nodes
  32. set_fact:
  33. new_node_status: true
  34. when: diff_output.stdout
  35. rescue:
  36. - name: No new nodes
  37. debug:
  38. msg: "No new nodes to add"
  39. verbosity: 2
  40. when: backup_map_status
  41. - name: Fetch inputs from mapping file
  42. command: awk 'NR > 1 { print }' {{ temp_host_mapping_file }}
  43. changed_when: false
  44. register: fetch_mapping_file
  45. - name: Fetch input
  46. blockinfile:
  47. path: "{{ role_path }}/files/dhcp.template"
  48. insertafter: '^#insert the static DHCP leases for configuration here'
  49. block: |
  50. host {{ item.split(',')[1] }} {
  51. hardware ethernet {{ item.split(',')[0] }};
  52. fixed-address {{ item.split(',')[2] }};
  53. option domain-name "{{ domain_name }}";
  54. }
  55. marker: "# {mark} DHCP BLOCK OF {{ item.split(',')[0] }}"
  56. when: (not cobbler_image_status) or (new_node_status)
  57. failed_when: false
  58. with_items: "{{ fetch_mapping_file.stdout_lines }}"
  59. tags: install
  60. - name: Create a backup file
  61. copy:
  62. src: "{{ temp_host_mapping_file }}"
  63. dest: "{{ role_path }}/files/backup_host_mapping_file.csv"
  64. mode: "{{ temp_file_perm }}"
  65. - name: Get cobbler pod name
  66. command: 'kubectl get pod -n {{ cobbler_namespace }} -l app=cobbler -o jsonpath="{.items[0].metadata.name}"'
  67. changed_when: false
  68. register: cobbler_pod_name
  69. when: cobbler_container_status
  70. tags: install
  71. - name: Copy the dhcp.template inside container
  72. command: 'kubectl exec --stdin --tty -n {{ cobbler_namespace }} {{ cobbler_pod_name.stdout }} \
  73. -- cp /root/omnia/control_plane/roles/provision_cobbler/files/dhcp.template /etc/cobbler/dhcp.template'
  74. when: ( cobbler_container_status ) and ( new_node_status )
  75. - name: Cobbler sync for adding new nodes
  76. command: 'kubectl exec --stdin --tty -n {{ cobbler_namespace }} {{ cobbler_pod_name.stdout }} -- cobbler sync'
  77. when: ( cobbler_container_status ) and ( new_node_status )
  78. - name: Restart dhcpd
  79. command: 'kubectl exec --stdin --tty -n {{ cobbler_namespace }} {{ cobbler_pod_name.stdout }} -- systemctl restart dhcpd'
  80. when: ( cobbler_container_status ) and ( new_node_status )