fetch_password.yml 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. mode: '0600'
  31. when: not vault_key_result.stat.exists
  32. - name: Check if omnia config file is encrypted
  33. command: cat {{ role_path }}/../../{{ config_filename }}
  34. changed_when: false
  35. register: config_content
  36. no_log: True
  37. - name: Decrpyt omnia_config.yml
  38. command: >-
  39. ansible-vault decrypt {{ role_path }}/../../{{ config_filename }}
  40. --vault-password-file {{ role_path }}/../../{{ config_vaultname }}
  41. when: "'$ANSIBLE_VAULT;' in config_content.stdout"
  42. - name: Include variable file omnia_config.yml
  43. include_vars: "{{ role_path }}/../../{{ config_filename }}"
  44. no_log: True
  45. - name: Validate input parameters are not empty
  46. fail:
  47. msg: "{{ input_config_failure_msg }}"
  48. register: input_config_check
  49. when:
  50. - mariadb_password | length < 1 or
  51. k8s_cni | length < 1 or
  52. k8s_pod_network_cidr | length < 1
  53. - name: Assert mariadb_password
  54. assert:
  55. that:
  56. - mariadb_password | length > min_length | int - 1
  57. - mariadb_password | length < max_length | int + 1
  58. - '"-" not in mariadb_password '
  59. - '"\\" not in mariadb_password '
  60. - '"\"" not in mariadb_password '
  61. - " \"'\" not in mariadb_password "
  62. success_msg: "{{ success_msg_mariadb_password }}"
  63. fail_msg: "{{ fail_msg_mariadb_password }}"
  64. - name: Assert kubernetes cni
  65. assert:
  66. that: "('calico' in k8s_cni) or ('flannel' in k8s_cni)"
  67. success_msg: "{{ success_msg_k8s_cni }}"
  68. fail_msg: "{{ fail_msg_k8s_cni }}"
  69. - name: Assert kubernetes pod network CIDR
  70. assert:
  71. that:
  72. - k8s_pod_network_cidr | length > 9
  73. - '"/" in k8s_pod_network_cidr '
  74. success_msg: "{{ success_msg_k8s_pod_network_cidr }}"
  75. fail_msg: "{{ fail_msg_k8s_pod_network_cidr }}"
  76. - name: Save input variables from file
  77. set_fact:
  78. db_password: "{{ mariadb_password }}"
  79. k8s_cni: "{{ k8s_cni }}"
  80. k8s_pod_network_cidr: "{{ k8s_pod_network_cidr }}"
  81. no_log: True
  82. - name: Encrypt input config file
  83. command: >-
  84. ansible-vault encrypt {{ role_path }}/../../{{ config_filename }}
  85. --vault-password-file {{ role_path }}/../../{{ config_vaultname }}
  86. changed_when: false