awx_password.yml 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. #Tasks for getting and encrypting AWX Password
  16. - name: Clone AWX repo
  17. git:
  18. repo: "{{ awx_git_repo }}"
  19. dest: "{{ awx_repo_path }}"
  20. force: yes
  21. tags: install
  22. - name: AWX password
  23. block:
  24. - name: Take awx password
  25. pause:
  26. prompt: "{{ prompt_password }}"
  27. echo: no
  28. register: prompt_admin_password
  29. until:
  30. - prompt_admin_password.user_input | length > min_length| int - 1
  31. - '"-" not in prompt_admin_password.user_input '
  32. - '"\\" not in prompt_admin_password.user_input '
  33. - '"\"" not in prompt_admin_password.user_input '
  34. - " \"'\" not in prompt_admin_password.user_input "
  35. retries: "{{ retries }}"
  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_password_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. - '"-" not in admin_password '
  48. - '"\\" not in admin_password '
  49. - '"\"" not in admin_password '
  50. - " \"'\" not in admin_password "
  51. success_msg: "{{ success_msg_pwd_format }}"
  52. fail_msg: "{{ fail_msg_pwd_format }}"
  53. register: msg_pwd_format
  54. when: admin_password is defined and no_prompt is defined
  55. - name: Save admin password
  56. set_fact:
  57. admin_password: "{{ prompt_admin_password.user_input }}"
  58. when: no_prompt is not defined
  59. - name: Confirmation
  60. block:
  61. - name: Confirm AWX password
  62. pause:
  63. prompt: "{{ confirm_password }}"
  64. echo: no
  65. register: prompt_admin_password_confirm
  66. until: admin_password == prompt_admin_password_confirm.user_input
  67. retries: "{{ confirm_retries }}"
  68. delay: "{{ retry_delay }}"
  69. when: admin_password_confirm is not defined and no_prompt is not defined
  70. rescue:
  71. - name: Abort if password confirmation failed
  72. fail:
  73. msg: "{{ msg_failed_password_confirm }}"
  74. tags: install
  75. - name: Assert admin_password_confirm if prompt not given
  76. assert:
  77. that: admin_password == admin_password_confirm
  78. success_msg: "{{ success_msg_pwd_confirm }}"
  79. fail_msg: "{{ fail_msg_pwd_confirm }}"
  80. register: msg_pwd_confirm
  81. when: admin_password_confirm is defined and no_prompt is defined
  82. - name: Create ansible vault key
  83. set_fact:
  84. vault_key: "{{ lookup('password', '/dev/null chars=ascii_letters') }}"
  85. tags: install
  86. - name: Save vault key
  87. copy:
  88. dest: "{{ awx_installer_path + vault_file }}"
  89. content: |
  90. {{ vault_key }}
  91. owner: root
  92. force: yes
  93. tags: install
  94. - name: Encrypt awx password
  95. command: ansible-vault encrypt_string "{{ admin_password }}" --name admin_password --vault-password-file "{{ vault_file }}"
  96. register: encrypt_password
  97. args:
  98. chdir: "{{ awx_installer_path }}"
  99. tags: install
  100. - name: Store encrypted password
  101. copy:
  102. dest: "{{ awx_installer_path + awx_password_file }}"
  103. content: |
  104. ---
  105. {{ encrypt_password.stdout }}
  106. force: yes
  107. owner: root
  108. tags: install