password_config.yml 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 input config file is encrypted
  16. command: cat {{ input_config_filename }}
  17. changed_when: false
  18. register: config_content
  19. - name: Decrpyt input_config.yml
  20. command: ansible-vault decrypt {{ input_config_filename }} --vault-password-file {{ role_path }}/files/{{ vault_filename }}
  21. changed_when: false
  22. when: "'$ANSIBLE_VAULT;' in config_content.stdout"
  23. - name: Include variable file input_config.yml
  24. include_vars: "{{ input_config_filename }}"
  25. - name: Validate input parameters are not empty
  26. fail:
  27. msg: "{{ input_config_failure_msg }}"
  28. register: input_config_check
  29. when: (provision_password | length < 1) or (awx_password | length < 1) or (mariadb_password | length < 1) or (hpc_nic | length < 1) or (public_nic | length < 1)
  30. - name: Save input variables from file
  31. set_fact:
  32. cobbler_password: "{{ provision_password }}"
  33. admin_password: "{{ awx_password }}"
  34. input_mariadb_password: "{{ mariadb_password }}"
  35. nic: "{{ hpc_nic }}"
  36. internet_nic: "{{ public_nic }}"
  37. - name: Assert provision_password
  38. assert:
  39. that:
  40. - cobbler_password | length > min_length | int - 1
  41. - cobbler_password | length < max_length | int + 1
  42. - '"-" not in cobbler_password '
  43. - '"\\" not in cobbler_password '
  44. - '"\"" not in cobbler_password '
  45. - " \"'\" not in cobbler_password "
  46. success_msg: "{{ success_msg_provision_password }}"
  47. fail_msg: "{{ fail_msg_provision_password }}"
  48. register: cobbler_password_check
  49. - name: Assert awx_password
  50. assert:
  51. that:
  52. - admin_password | length > min_length | int - 1
  53. - admin_password | length < max_length | int + 1
  54. - '"-" not in admin_password '
  55. - '"\\" not in admin_password '
  56. - '"\"" not in admin_password '
  57. - " \"'\" not in admin_password "
  58. success_msg: "{{ success_msg_awx_password }}"
  59. fail_msg: "{{ fail_msg_awx_password }}"
  60. register: awx_password_check
  61. - name: Assert mariadb_password
  62. assert:
  63. that:
  64. - input_mariadb_password | length > min_length | int - 1
  65. - input_mariadb_password | length < max_length | int + 1
  66. - '"-" not in input_mariadb_password '
  67. - '"\\" not in input_mariadb_password '
  68. - '"\"" not in input_mariadb_password '
  69. - " \"'\" not in input_mariadb_password "
  70. success_msg: "{{ success_msg_mariadb_password }}"
  71. fail_msg: "{{ fail_msg_mariadb_password }}"
  72. register: mariadb_password_check
  73. - name: Assert hpc_nic
  74. assert:
  75. that:
  76. - nic | length > nic_min_length | int - 1
  77. - nic != internet_nic
  78. success_msg: "{{ success_msg_hpc_nic }}"
  79. fail_msg: "{{ fail_msg_hpc_nic }}"
  80. register: hpc_nic_check
  81. - name: Assert public_nic
  82. assert:
  83. that:
  84. - internet_nic | length > nic_min_length | int - 1
  85. - nic != internet_nic
  86. - "('em1' in internet_nic) or ('em2' in internet_nic) or ('em3' in internet_nic)"
  87. success_msg: "{{ success_msg_public_nic }}"
  88. fail_msg: "{{ fail_msg_public_nic }}"
  89. register: public_nic_check
  90. - name: Create ansible vault key
  91. set_fact:
  92. vault_key: "{{ lookup('password', '/dev/null chars=ascii_letters') }}"
  93. when: "'$ANSIBLE_VAULT;' not in config_content.stdout"
  94. - name: Save vault key
  95. copy:
  96. dest: "{{ role_path }}/files/{{ vault_filename }}"
  97. content: |
  98. {{ vault_key }}
  99. owner: root
  100. force: yes
  101. when: "'$ANSIBLE_VAULT;' not in config_content.stdout"
  102. - name: Encrypt input config file
  103. command: ansible-vault encrypt {{ input_config_filename }} --vault-password-file {{ role_path }}/files/{{ vault_filename }}
  104. changed_when: false