fetch_password.yml 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 if omnia_vault_key exists
  16. stat:
  17. path: "{{ role_path }}/../../{{ config_vaultname }}"
  18. register: vault_key_result
  19. - name: Create ansible vault key if it does not exist
  20. set_fact:
  21. vault_key: "{{ lookup('password', '/dev/null chars=ascii_letters') }}"
  22. when: not vault_key_result.stat.exists
  23. - name: Save vault key
  24. copy:
  25. dest: "{{ role_path }}/../../{{ config_vaultname }}"
  26. content: |
  27. {{ vault_key }}
  28. owner: root
  29. force: yes
  30. when: not vault_key_result.stat.exists
  31. - name: Check if omnia config file is encrypted
  32. command: cat {{ role_path }}/../../{{ config_filename }}
  33. changed_when: false
  34. register: config_content
  35. no_log: True
  36. - name: Decrpyt omnia_config.yml
  37. command: >-
  38. ansible-vault decrypt {{ role_path }}/../../{{ config_filename }}
  39. --vault-password-file {{ role_path }}/../../{{ config_vaultname }}
  40. when: "'$ANSIBLE_VAULT;' in config_content.stdout"
  41. - name: Include variable file omnia_config.yml
  42. include_vars: "{{ role_path }}/../../{{ config_filename }}"
  43. no_log: True
  44. - name: Validate input parameters are not empty
  45. fail:
  46. msg: "{{ input_config_failure_msg }}"
  47. register: input_config_check
  48. when:
  49. - mariadb_password | length < 1 or
  50. k8s_cni | length < 1
  51. - name: Assert mariadb_password
  52. assert:
  53. that:
  54. - mariadb_password | length > min_length | int - 1
  55. - mariadb_password | length < max_length | int + 1
  56. - '"-" not in mariadb_password '
  57. - '"\\" not in mariadb_password '
  58. - '"\"" not in mariadb_password '
  59. - " \"'\" not in mariadb_password "
  60. success_msg: "{{ success_msg_mariadb_password }}"
  61. fail_msg: "{{ fail_msg_mariadb_password }}"
  62. - name: Assert kubernetes cni
  63. assert:
  64. that: "('calico' in k8s_cni) or ('flannel' in k8s_cni)"
  65. success_msg: "{{ success_msg_k8s_cni }}"
  66. fail_msg: "{{ fail_msg_k8s_cni }}"
  67. - name: Save input variables from file
  68. set_fact:
  69. db_password: "{{ mariadb_password }}"
  70. k8s_cni: "{{ k8s_cni }}"
  71. no_log: True
  72. - name: Encrypt input config file
  73. command: >-
  74. ansible-vault encrypt {{ role_path }}/../../{{ config_filename }}
  75. --vault-password-file {{ role_path }}/../../{{ config_vaultname }}
  76. changed_when: false