validate_login_vars.yml 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # Copyright 2022 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 login_vars file is encrypted
  16. command: cat {{ login_vars_file }}
  17. changed_when: false
  18. register: config_content
  19. no_log: true
  20. - name: Decrpyt login_vars.yml
  21. command: >-
  22. ansible-vault decrypt {{ login_vars_file }}
  23. --vault-password-file {{ vault_filename }}
  24. changed_when: false
  25. when: "'$ANSIBLE_VAULT;' in config_content.stdout"
  26. - name: Include variable file login_vars.yml
  27. include_vars: "{{ login_vars_file }}"
  28. no_log: true
  29. - name: Assert usernames and passwords in login_vars.yml
  30. block:
  31. - name: Assert timescaledb user name
  32. assert:
  33. that: timescaledb_user | length > 1
  34. no_log: true
  35. - name: Assert timescaledb user password
  36. assert:
  37. that: timescaledb_password | length > 1
  38. no_log: true
  39. - name: Assert mysqldb user name
  40. assert:
  41. that: mysqldb_user | length > 1
  42. no_log: true
  43. - name: Assert mysqldb user password
  44. assert:
  45. that: mysqldb_password | length > 1
  46. no_log: true
  47. - name: Assert mysqldb root user password
  48. assert:
  49. that: mysqldb_root_password | length > 1
  50. no_log: true
  51. rescue:
  52. - name: Validation issue in login/vars.yml
  53. fail:
  54. msg: "{{ login_vars_fail_msg }}"
  55. - name: Create ansible vault key
  56. set_fact:
  57. vault_key: "{{ lookup('password', '/dev/null chars=ascii_letters') }}"
  58. when: "'$ANSIBLE_VAULT;' not in config_content.stdout"
  59. - name: Save vault key
  60. copy:
  61. dest: "{{ vault_filename }}"
  62. content: |
  63. {{ vault_key }}
  64. owner: root
  65. force: yes
  66. mode: "{{ vault_file_perm }}"
  67. when: "'$ANSIBLE_VAULT;' not in config_content.stdout"
  68. - name: Encrypt input config file
  69. command: >-
  70. ansible-vault encrypt {{ login_vars_file }}
  71. --vault-password-file {{ vault_filename }}
  72. changed_when: false