validate_login_vars.yml 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. # Copyright 2022 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. # Include telemetry_login_vars.yml
  16. - name: Check telemetry_login_vars file is encrypted
  17. command: cat {{ login_vars_file }}
  18. changed_when: false
  19. register: config_content
  20. no_log: true
  21. - name: Decrpyt telemetry_login_vars.yml
  22. command: >-
  23. ansible-vault decrypt {{ login_vars_file }}
  24. --vault-password-file {{ vault_filename }}
  25. changed_when: false
  26. when: "'$ANSIBLE_VAULT;' in config_content.stdout"
  27. - name: Include variable file telemetry_login_vars.yml
  28. include_vars: "{{ login_vars_file }}"
  29. no_log: true
  30. - name: Assert usernames and passwords in telemetry_login_vars.yml
  31. block:
  32. - name: Assert timescaledb user name
  33. assert:
  34. that:
  35. - timescaledb_user | length > 1
  36. - '"-" not in timescaledb_user '
  37. - '"\\" not in timescaledb_user '
  38. - '"\"" not in timescaledb_user '
  39. - " \"'\" not in timescaledb_user "
  40. no_log: true
  41. - name: Assert timescaledb user password
  42. assert:
  43. that:
  44. - timescaledb_password | length > 1
  45. - '"-" not in timescaledb_password '
  46. - '"\\" not in timescaledb_password '
  47. - '"\"" not in timescaledb_password '
  48. - " \"'\" not in timescaledb_password "
  49. no_log: true
  50. - name: Assert mysqldb user name
  51. assert:
  52. that:
  53. - mysqldb_user | length > 1
  54. - '"-" not in mysqldb_user '
  55. - '"\\" not in mysqldb_user '
  56. - '"\"" not in mysqldb_user '
  57. - " \"'\" not in mysqldb_user "
  58. no_log: true
  59. - name: Assert mysqldb user password
  60. assert:
  61. that:
  62. - mysqldb_password | length > 1
  63. - '"-" not in mysqldb_password '
  64. - '"\\" not in mysqldb_password '
  65. - '"\"" not in mysqldb_password '
  66. - " \"'\" not in mysqldb_password "
  67. no_log: true
  68. - name: Assert mysqldb root user password
  69. assert:
  70. that:
  71. - mysqldb_root_password | length > 1
  72. - '"-" not in mysqldb_root_password '
  73. - '"\\" not in mysqldb_root_password '
  74. - '"\"" not in mysqldb_root_password '
  75. - " \"'\" not in mysqldb_root_password "
  76. no_log: true
  77. rescue:
  78. - name: Validation issue in telemetry_login_vars.yml
  79. fail:
  80. msg: "{{ login_vars_fail_msg }}"
  81. - name: Create ansible vault key
  82. set_fact:
  83. vault_key: "{{ lookup('password', '/dev/null chars=ascii_letters') }}"
  84. when: "'$ANSIBLE_VAULT;' not in config_content.stdout"
  85. - name: Save vault key
  86. copy:
  87. dest: "{{ vault_filename }}"
  88. content: |
  89. {{ vault_key }}
  90. owner: root
  91. force: yes
  92. mode: "{{ vault_file_perm }}"
  93. when: "'$ANSIBLE_VAULT;' not in config_content.stdout"
  94. - name: Encrypt input config file
  95. command: >-
  96. ansible-vault encrypt {{ login_vars_file }}
  97. --vault-password-file {{ vault_filename }}
  98. changed_when: false
  99. # Include control_plane/login_vars.yml
  100. - name: Check login_vars file is encrypted
  101. command: cat {{ ctrl_plane_login_vars_filename }}
  102. changed_when: false
  103. register: config_content
  104. no_log: true
  105. - name: Decrpyt login_vars.yml
  106. command: >-
  107. ansible-vault decrypt {{ ctrl_plane_login_vars_filename }}
  108. --vault-password-file {{ ctrl_plane_login_vault_filename }}
  109. changed_when: false
  110. when: "'$ANSIBLE_VAULT;' in config_content.stdout"
  111. - name: Include variable file control_plane/login_vars.yml
  112. include_vars: "{{ ctrl_plane_login_vars_filename }}"
  113. no_log: true
  114. - name: Assert grafana credentials
  115. block:
  116. - name: Assert grafana_username and grafana_username
  117. assert:
  118. that:
  119. - grafana_username | length >= min_length_grafana
  120. - grafana_username | length <= max_length
  121. - '"-" not in grafana_username '
  122. - '"\\" not in grafana_username '
  123. - '"\"" not in grafana_username '
  124. - " \"'\" not in grafana_username "
  125. - grafana_password | length >= min_length_grafana
  126. - grafana_password | length <= max_length
  127. - not grafana_password == 'admin'
  128. - '"-" not in grafana_password '
  129. - '"\\" not in grafana_password '
  130. - '"\"" not in grafana_password '
  131. - " \"'\" not in grafana_password "
  132. no_log: true
  133. rescue:
  134. - name: Validation issue in control_plane/login_vars.yml
  135. fail:
  136. msg: "{{ ctrl_plane_login_vars_fail_msg }}"
  137. - name: Create ansible vault key
  138. set_fact:
  139. vault_key: "{{ lookup('password', '/dev/null chars=ascii_letters') }}"
  140. when: "'$ANSIBLE_VAULT;' not in config_content.stdout"
  141. - name: Save vault key
  142. copy:
  143. dest: "{{ ctrl_plane_login_vault_filename }}"
  144. content: |
  145. {{ vault_key }}
  146. owner: root
  147. force: yes
  148. mode: "{{ vault_file_perm }}"
  149. when: "'$ANSIBLE_VAULT;' not in config_content.stdout"
  150. - name: Encrypt input config file
  151. command: >-
  152. ansible-vault encrypt {{ ctrl_plane_login_vars_filename }}
  153. --vault-password-file {{ ctrl_plane_login_vault_filename }}
  154. changed_when: false