fetch_password.yml 4.1 KB

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