mapping_file.yml 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # Copyright 2020 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: Check availability of mapping file
  16. stat:
  17. path: "{{ role_path }}/files/{{ mapping_file_name }}"
  18. register: mapping_file_status
  19. tags: install
  20. - name: Mapping file not present
  21. fail:
  22. msg: "{{ mapping_file_fail }}"
  23. when: mapping_file_status.stat.exists == false
  24. register: mapping_file_check
  25. tags: install
  26. - name: Remove blank lines
  27. shell: awk -F, 'length>NF+1' {{ role_path }}/files/{{ mapping_file_name }} > {{ role_path }}/files/new_mapping_file.csv
  28. changed_when: false
  29. tags: install
  30. - name: Remove blank spaces
  31. shell: sed -i.bak -E 's/(^|,)[[:blank:]]+/\1/g; s/[[:blank:]]+(,|$)/\1/g' {{ role_path }}/files/new_mapping_file.csv
  32. args:
  33. warn: no
  34. changed_when: false
  35. tags: install
  36. - name: Count the rows
  37. shell: awk -F',' '{print $2}' {{ role_path }}/files/new_mapping_file.csv | wc -l
  38. register: total_count
  39. changed_when: false
  40. tags: install
  41. - name: Check for duplicate hostname
  42. shell: awk -F',' '{print $2}' {{ role_path }}/files/new_mapping_file.csv | uniq | wc -l
  43. register: count_host
  44. changed_when: false
  45. tags: install
  46. - name: Fail if duplicate hosts exist
  47. fail:
  48. msg: "{{ fail_hostname_duplicate }}"
  49. when: total_count.stdout > count_host.stdout
  50. tags: install
  51. - name: Check if _ or . or space present in hostname
  52. shell: awk -F',' '{print $2}' {{ role_path }}/files/new_mapping_file.csv |grep -E -- '_|\.| '
  53. register: hostname_result
  54. ignore_errors: true
  55. changed_when: false
  56. tags: install
  57. - name: Fail if _ or . or space present in hostname
  58. fail:
  59. msg: "{{ hostname_result.stdout + ' :Hostname should not contain _ or . as it will cause error with slurm and K8s'}}"
  60. when: hostname_result.stdout != ""
  61. tags: install
  62. - name: Fetch input
  63. blockinfile:
  64. path: "{{ role_path }}/files/dhcp.template"
  65. insertafter: '^#insert the static DHCP leases for configuration here'
  66. block: |
  67. host {{ item.split(',')[1] }} {
  68. hardware ethernet {{ item.split(',')[0] }};
  69. fixed-address {{ item.split(',')[2] }};
  70. }
  71. marker: "# {mark} DHCP BLOCK OF {{ item.split(',')[0] }}"
  72. with_lines: "{{ remove_header }}"
  73. ignore_errors: true
  74. tags: install