provision_password.yml 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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: 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: 0644
  25. tags: install
  26. - name: Take provision Password
  27. block:
  28. - name: Provision Password (Min length should be 8)
  29. pause:
  30. prompt: "{{ prompt_password }}"
  31. echo: no
  32. register: prompt_admin_password
  33. until:
  34. - prompt_admin_password.user_input | length > min_length| int - 1
  35. retries: "{{ no_of_retry }}"
  36. delay: "{{ retry_delay }}"
  37. when: admin_password is not defined and no_prompt is not defined
  38. rescue:
  39. - name: Abort if password validation fails
  40. fail:
  41. msg: "{{ msg_incorrect_format }}"
  42. tags: install
  43. - name: Assert admin_password if prompt not given
  44. assert:
  45. that:
  46. - admin_password | length > min_length| int - 1
  47. success_msg: "{{ success_msg_pwd_format }}"
  48. fail_msg: "{{ fail_msg_pwd_format }}"
  49. register: msg_pwd_format
  50. when: admin_password is defined and no_prompt is defined
  51. tags: install
  52. - name: Save admin password
  53. set_fact:
  54. admin_password: "{{ prompt_admin_password.user_input }}"
  55. when: no_prompt is not defined
  56. tags: install
  57. - name: Confirm password
  58. block:
  59. - name: Confirm provision password
  60. pause:
  61. prompt: "{{ confirm_password }}"
  62. echo: no
  63. register: prompt_admin_password_confirm
  64. until: admin_password == prompt_admin_password_confirm.user_input
  65. retries: "{{ no_of_retry }}"
  66. delay: "{{ retry_delay }}"
  67. when: admin_password_confirm is not defined and no_prompt is not defined
  68. rescue:
  69. - name: Abort if password confirmation failed
  70. fail:
  71. msg: "{{ msg_failed_password_confirm }}"
  72. tags: install
  73. - name: Assert admin_password_confirm if prompt not given
  74. assert:
  75. that: admin_password == admin_password_confirm
  76. success_msg: "{{ success_msg_pwd_confirm }}"
  77. fail_msg: "{{ fail_msg_pwd_confirm }}"
  78. register: msg_pwd_confirm
  79. when: admin_password_confirm is defined and no_prompt is defined
  80. tags: install
  81. - name: Encrypt cobbler password
  82. shell: >
  83. set -o pipefail && \
  84. digest="$( printf "%s:%s:%s" {{ username }} "Cobbler" {{ admin_password }} | md5sum | awk '{print $1}' )"
  85. printf "%s:%s:%s\n" "{{ username }}" "Cobbler" "$digest" > "{{ role_path }}/files/.users.digest"
  86. args:
  87. executable: /bin/bash
  88. changed_when: false
  89. tags: install
  90. - name: Read password file
  91. set_fact:
  92. var: "{{ lookup('file', role_path+'/files/.users.digest').splitlines() }}"
  93. tags: install
  94. - name: Get encrypted password
  95. set_fact:
  96. encrypted_pass: "{{ var[0].split(':')[2] }}"
  97. - name: Create the kickstart file
  98. copy:
  99. src: "{{ role_path }}/files/temp_centos8.ks"
  100. dest: "{{ role_path }}/files/centos8.ks"
  101. mode: 0775
  102. tags: install
  103. - name: Configure kickstart file
  104. replace:
  105. path: "{{ role_path }}/files/centos8.ks"
  106. regexp: '^url --url http://ip/cblr/links/CentOS8-x86_64/'
  107. replace: url --url http://{{ ansible_eno2.ipv4.address }}/cblr/links/CentOS8-x86_64/
  108. tags: install
  109. - name: Random phrase generation
  110. command: openssl rand -base64 12
  111. changed_when: false
  112. register: prompt_random_phrase
  113. tags: install
  114. - name: Set random phrase
  115. set_fact:
  116. random_phrase: "{{ prompt_random_phrase.stdout }}"
  117. tags: install
  118. - name: Login password
  119. command: openssl passwd -1 -salt {{ random_phrase }} {{ admin_password }}
  120. changed_when: false
  121. register: login_pass
  122. tags: install
  123. - name: Configure kickstart file
  124. replace:
  125. path: "{{ role_path }}/files/centos8.ks"
  126. regexp: '^rootpw --iscrypted password'
  127. replace: 'rootpw --iscrypted {{ login_pass.stdout }}'
  128. tags: install