provision_password.yml 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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: Encrypt cobbler password
  27. shell: printf "%s:%s:%s" {{ username }} "Cobbler" {{ cobbler_password }} | md5sum | awk '{print $1}'
  28. changed_when: false
  29. register: encrypt_password
  30. tags: install
  31. - name: Copy cobbler password to cobbler config file
  32. shell: printf "%s:%s:%s\n" "{{ username }}" "Cobbler" "{{ encrypt_password.stdout }}" > "{{ role_path }}/files/.users.digest"
  33. changed_when: false
  34. tags: install
  35. - name: Create the kickstart file
  36. copy:
  37. src: "{{ role_path }}/files/temp_centos7.ks"
  38. dest: "{{ role_path }}/files/centos7.ks"
  39. mode: 0775
  40. tags: install
  41. - name: Configure kickstart file
  42. replace:
  43. path: "{{ role_path }}/files/centos7.ks"
  44. regexp: '^url --url http://ip/cblr/links/CentOS7-x86_64/'
  45. replace: url --url http://{{ ansible_em1.ipv4.address }}/cblr/links/CentOS7-x86_64/
  46. when: internet_nic == "em1"
  47. tags: install
  48. - name: Configure kickstart file
  49. replace:
  50. path: "{{ role_path }}/files/centos7.ks"
  51. regexp: '^url --url http://ip/cblr/links/CentOS7-x86_64/'
  52. replace: url --url http://{{ ansible_em2.ipv4.address }}/cblr/links/CentOS7-x86_64/
  53. when: internet_nic == "em2"
  54. tags: install
  55. - name: Configure kickstart file
  56. replace:
  57. path: "{{ role_path }}/files/centos7.ks"
  58. regexp: '^url --url http://ip/cblr/links/CentOS7-x86_64/'
  59. replace: url --url http://{{ ansible_em3.ipv4.address }}/cblr/links/CentOS7-x86_64/
  60. when: internet_nic == "em3"
  61. tags: install
  62. - name: Random phrase generation
  63. command: openssl rand -base64 12
  64. changed_when: false
  65. register: prompt_random_phrase
  66. tags: install
  67. - name: Set random phrase
  68. set_fact:
  69. random_phrase: "{{ prompt_random_phrase.stdout }}"
  70. tags: install
  71. - name: Login password
  72. command: openssl passwd -1 -salt {{ random_phrase }} {{ cobbler_password }}
  73. changed_when: false
  74. register: login_pass
  75. tags: install
  76. - name: Configure kickstart file
  77. replace:
  78. path: "{{ role_path }}/files/centos7.ks"
  79. regexp: '^rootpw --iscrypted password'
  80. replace: 'rootpw --iscrypted {{ login_pass.stdout }}'
  81. tags: install
  82. - name: Configure kickstart file
  83. replace:
  84. path: "{{ role_path }}/files/centos7.ks"
  85. regexp: '^network --bootproto=dhcp --device=nic --onboot=on'
  86. replace: 'network --bootproto=dhcp --device={{ nic }} --onboot=on'
  87. tags: install
  88. - name: Configure default password in settings
  89. local_action: copy content="{{ login_pass.stdout }}" dest="{{ role_path }}/files/.node_login.digest"
  90. tags: install