verify_omnia_params.yml 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. # Copyright 2021 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: "{{ vault_file_perm }}"
  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_omnia_failure_msg }}"
  48. register: input_config_check
  49. when:
  50. - mariadb_password | length < 1 or
  51. k8s_version | length < 1 or
  52. k8s_cni | 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 version
  65. assert:
  66. that: "('1.16.7' in k8s_version) or ('1.19.3' in k8s_version)"
  67. success_msg: "{{ success_msg_k8s_version }}"
  68. fail_msg: "{{ fail_msg_k8s_version }}"
  69. - name: Assert kubernetes cni
  70. assert:
  71. that: "('calico' in k8s_cni) or ('flannel' in k8s_cni)"
  72. success_msg: "{{ success_msg_k8s_cni }}"
  73. fail_msg: "{{ fail_msg_k8s_cni }}"
  74. - name: Save input variables from file
  75. set_fact:
  76. db_password: "{{ mariadb_password }}"
  77. k8s_version: "{{ k8s_version }}"
  78. k8s_cni: "{{ k8s_cni }}"
  79. docker_username: "{{ docker_username }}"
  80. docker_password: "{{ docker_password }}"
  81. no_log: True
  82. - name: Validate the domain name
  83. assert:
  84. that:
  85. - domain_name is regex("^(?!-)[A-Za-z0-9-]+([\\-\\.]{1}[a-z0-9]+)*\\.[A-Za-z]{2,6}$")
  86. success_msg: "{{ domain_name_success_msg }}"
  87. fail_msg: "{{ domain_name_fail_msg }}"
  88. when: domain_name | length > 0
  89. - name: Encrypt input config file
  90. command: >-
  91. ansible-vault encrypt {{ role_path }}/../../../{{ config_filename }}
  92. --vault-password-file {{ role_path }}/../../../{{ config_vaultname }}
  93. changed_when: false
  94. - name: Update omnia_config.yml permission
  95. file:
  96. path: "{{ role_path }}/../../../{{ config_filename }}"
  97. mode: "{{ vault_file_perm }}"