fetch_password.yml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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_version | length < 1 or
  52. k8s_cni | length < 1 or
  53. k8s_pod_network_cidr | length < 1 or
  54. ansible_config_file_path | length < 1
  55. - name: Assert mariadb_password
  56. assert:
  57. that:
  58. - mariadb_password | length > min_length | int - 1
  59. - mariadb_password | length < max_length | int + 1
  60. - '"-" not in mariadb_password '
  61. - '"\\" not in mariadb_password '
  62. - '"\"" not in mariadb_password '
  63. - " \"'\" not in mariadb_password "
  64. success_msg: "{{ success_msg_mariadb_password }}"
  65. fail_msg: "{{ fail_msg_mariadb_password }}"
  66. - name: Assert kubernetes version
  67. assert:
  68. that: "('1.16.7' in k8s_version) or ('1.19.3' in k8s_version)"
  69. success_msg: "{{ success_msg_k8s_version }}"
  70. fail_msg: "{{ fail_msg_k8s_version }}"
  71. - name: Assert kubernetes cni
  72. assert:
  73. that: "('calico' in k8s_cni) or ('flannel' in k8s_cni)"
  74. success_msg: "{{ success_msg_k8s_cni }}"
  75. fail_msg: "{{ fail_msg_k8s_cni }}"
  76. - name: Assert kubernetes pod network CIDR
  77. assert:
  78. that:
  79. - k8s_pod_network_cidr | length > 9
  80. - '"/" in k8s_pod_network_cidr '
  81. success_msg: "{{ success_msg_k8s_pod_network_cidr }}"
  82. fail_msg: "{{ fail_msg_k8s_pod_network_cidr }}"
  83. - name: Save input variables from file
  84. set_fact:
  85. db_password: "{{ mariadb_password }}"
  86. k8s_version: "{{ k8s_version }}"
  87. k8s_cni: "{{ k8s_cni }}"
  88. k8s_pod_network_cidr: "{{ k8s_pod_network_cidr }}"
  89. docker_username: "{{ docker_username }}"
  90. docker_password: "{{ docker_password }}"
  91. ansible_conf_file_path: "{{ ansible_config_file_path }}"
  92. no_log: True
  93. - name: Check whether ansible config file exists
  94. stat:
  95. path: "{{ ansible_conf_file_path }}/ansible.cfg"
  96. register: ansible_conf_exists
  97. - name: Create the directory if it does not exist
  98. file:
  99. path: "{{ ansible_conf_file_path }}"
  100. state: directory
  101. mode: "{{ file_perm }}"
  102. when: not ansible_conf_exists.stat.exists
  103. - name: Create ansible config file if it does not exist
  104. copy:
  105. dest: "{{ ansible_conf_file_path }}/ansible.cfg"
  106. mode: "{{ file_perm }}"
  107. content: |
  108. [defaults]
  109. log_path = /var/log/omnia.log
  110. when: not ansible_conf_exists.stat.exists
  111. - name: Set omnia.log file
  112. replace:
  113. path: "{{ ansible_conf_file_path }}/ansible.cfg"
  114. regexp: '#log_path = /var/log/ansible.log'
  115. replace: 'log_path = /var/log/omnia.log'
  116. when: ansible_conf_exists.stat.exists
  117. - name: Encrypt input config file
  118. command: >-
  119. ansible-vault encrypt {{ role_path }}/../../{{ config_filename }}
  120. --vault-password-file {{ role_path }}/../../{{ config_vaultname }}
  121. changed_when: false