fetch_grafana_cred.yml 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. - name: Check login_vars file is encrypted
  16. command: cat "{{ role_path }}/../../control_plane/{{ login_vars_filename }}"
  17. changed_when: false
  18. register: config_content
  19. no_log: true
  20. - name: Decrpyt login_vars.yml
  21. command: >-
  22. ansible-vault decrypt "{{ role_path }}/../../control_plane/{{ login_vars_filename }}"
  23. --vault-password-file "{{ role_path }}/../../control_plane/{{ vault_filename }}"
  24. changed_when: false
  25. when: "'$ANSIBLE_VAULT;' in config_content.stdout"
  26. - name: Include variable file login_vars.yml
  27. include_vars: "{{ role_path }}/../../control_plane/{{ login_vars_filename }}"
  28. no_log: true
  29. - name: Save grafana variables
  30. set_fact:
  31. grafana_username: '{{ grafana_username }}'
  32. grafana_password: '{{ grafana_password }}'
  33. no_log: True
  34. - name: Create ansible vault key
  35. set_fact:
  36. vault_key: "{{ lookup('password', '/dev/null chars=ascii_letters') }}"
  37. when: "'$ANSIBLE_VAULT;' not in config_content.stdout"
  38. - name: Save vault key
  39. copy:
  40. dest: "{{ role_path }}/../../control_plane/{{ vault_filename }}"
  41. content: |
  42. {{ vault_key }}
  43. owner: root
  44. force: yes
  45. mode: "{{ vault_file_perm }}"
  46. when: "'$ANSIBLE_VAULT;' not in config_content.stdout"
  47. - name: Encrypt input config file
  48. command: >-
  49. ansible-vault encrypt "{{ role_path }}/../../control_plane/{{ login_vars_filename }}"
  50. --vault-password-file "{{ role_path }}/../../control_plane/{{ vault_filename }}"
  51. changed_when: false
  52. - name: Update login_vars.yml permission
  53. file:
  54. path: "{{ role_path }}/../../control_plane/{{ login_vars_filename }}"
  55. mode: "{{ vault_file_perm }}"