validate_login_vars.yml 5.4 KB

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