provision_password.yml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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: Remove old user
  16. file:
  17. path: "{{ role_path }}/files/.users.digest"
  18. state: absent
  19. tags: install
  20. - name: Create a new user
  21. file:
  22. path: "{{ role_path }}/files/.users.digest"
  23. state: touch
  24. mode: "{{ user_mode }}"
  25. tags: install
  26. - name: Cobbler UI password
  27. set_fact:
  28. encrypt_password: "{{ cobbler_password | hash('sha3_256') }}"
  29. no_log: true
  30. tags: install
  31. - name: Copy cobbler password to cobbler config file
  32. shell: printf "%s:%s:%s\n" "{{ username }}" "Cobbler" "{{ encrypt_password }}" > "{{ role_path }}/files/.users.digest"
  33. changed_when: false
  34. no_log: true
  35. tags: install
  36. - name: Kickstart configuration - centos
  37. block:
  38. - name: Create the kickstart file
  39. copy:
  40. src: "{{ role_path }}/files/temp_centos7.ks"
  41. dest: "{{ role_path }}/files/{{ cobbler_kickstart_file }}"
  42. mode: 0775
  43. tags: install
  44. - name: Configure kickstart file - IP
  45. replace:
  46. path: "{{ role_path }}/files/{{ cobbler_kickstart_file }}"
  47. regexp: '^url --url http://ip/cblr/links/centos-x86_64/'
  48. replace: url --url http://{{ hpc_ip }}/cblr/links/centos-x86_64/
  49. tags: install
  50. - name: Configure kickstart file - nic
  51. lineinfile:
  52. path: "{{ role_path }}/files/{{ cobbler_kickstart_file }}"
  53. insertafter: '^network --bootproto=dhcp --device=link --onboot=on --activate'
  54. line: 'network --bootproto=dhcp --device={{ item }} --onboot=on --activate'
  55. tags: install
  56. with_items: "{{ centos_host_nic }}"
  57. when: provision_os == os_supported_centos
  58. - name: Kickstart configuration - rocky
  59. block:
  60. - name: Create the kickstart file
  61. copy:
  62. src: "{{ role_path }}/files/temp_rocky8.ks"
  63. dest: "{{ role_path }}/files/{{ cobbler_kickstart_file }}"
  64. mode: 0775
  65. tags: install
  66. - name: Configure kickstart file - IP
  67. replace:
  68. path: "{{ role_path }}/files/{{ cobbler_kickstart_file }}"
  69. regexp: '^url --url http://ip/cblr/links/rocky-x86_64/'
  70. replace: url --url http://{{ hpc_ip }}/cblr/links/rocky-x86_64/
  71. tags: install
  72. - name: Configure kickstart file - nic
  73. lineinfile:
  74. path: "{{ role_path }}/files/{{ cobbler_kickstart_file }}"
  75. insertafter: '^network --bootproto=dhcp --device=link --onboot=on --activate'
  76. line: 'network --bootproto=dhcp --device={{ item }} --onboot=on --activate'
  77. tags: install
  78. with_items: "{{ rocky_host_nic }}"
  79. when: provision_os == os_supported_rocky
  80. - name: Random phrase generation
  81. command: openssl rand -base64 12
  82. changed_when: false
  83. register: prompt_random_phrase
  84. tags: install
  85. no_log: true
  86. - name: Set random phrase
  87. set_fact:
  88. random_phrase: "{{ prompt_random_phrase.stdout }}"
  89. tags: install
  90. no_log: true
  91. - name: Login password
  92. command: openssl passwd -1 -salt {{ random_phrase }} {{ provision_password }}
  93. no_log: true
  94. changed_when: false
  95. register: login_pass
  96. tags: install
  97. - name: Assign password
  98. replace:
  99. path: "{{ role_path }}/files/settings.yaml"
  100. regexp: '^default_password_crypted: password'
  101. replace: 'default_password_crypted: {{ login_pass.stdout }}'
  102. no_log: true
  103. tags: install
  104. - name: Configure kickstart file - Password
  105. replace:
  106. path: "{{ role_path }}/files/{{ cobbler_kickstart_file }}"
  107. regexp: '^rootpw --iscrypted ks_password'
  108. replace: 'rootpw --iscrypted {{ login_pass.stdout }}'
  109. no_log: true
  110. tags: install
  111. - name: Configure kickstart file - timezone
  112. replace:
  113. path: "{{ role_path }}/files/{{ cobbler_kickstart_file }}"
  114. regexp: '^timezone --utc ks_timezone'
  115. replace: 'timezone --utc {{ timezone }}'
  116. tags: install
  117. - name: Configure kickstart file - language
  118. replace:
  119. path: "{{ role_path }}/files/{{ cobbler_kickstart_file }}"
  120. regexp: '^lang ks_language'
  121. replace: 'lang {{ language }}'
  122. tags: install
  123. - name: Remove ^M characters
  124. command: dos2unix {{ role_path }}/files/{{ cobbler_kickstart_file }}
  125. changed_when: false
  126. failed_when: false