configure_grafana.yml 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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: Include k8s_start_services variables
  16. include_vars: ../../k8s_start_services/vars/main.yml
  17. - block:
  18. - name: Create prometheus datasource in grafana
  19. community.grafana.grafana_datasource:
  20. name: "hpc-prometheus-{{ ansible_default_ipv4.address }}"
  21. grafana_url: "http://{{ grafana_svc_ip }}:{{ grafana_svc_port }}"
  22. grafana_user: "{{ hostvars['127.0.0.1']['grafana_username'] }}"
  23. grafana_password: "{{ hostvars['127.0.0.1']['grafana_password'] }}"
  24. ds_type: prometheus
  25. ds_url: "http://{{ ansible_default_ipv4.address }}:{{ nginx_listen_port }}"
  26. access: direct
  27. delegate_to: localhost
  28. no_log: true
  29. register: create_slurm_prom_datasource
  30. rescue:
  31. - name: Create prometheus datasource in grafana failed
  32. fail:
  33. msg: "Error: {{ create_slurm_prom_datasource.msg }}"
  34. - name: Replace data source in slurm dashboard
  35. replace:
  36. path: "{{ role_path }}/files/{{ item }}"
  37. regexp: '"uid": "hpc.*'
  38. replace: '"uid": "hpc-prometheus-{{ ansible_default_ipv4.address }}"'
  39. with_items: "{{ slurm_dashboard_json_files }}"
  40. delegate_to: localhost
  41. - name: Replace title in slurm dashboard (1/2)
  42. replace:
  43. path: "{{ role_path }}/files/slurm-dashboard-node-exporter.json"
  44. regexp: '"title": "SLURM - Node Exporter Server Metrics.*'
  45. replace: '"title": "SLURM - Node Exporter Server Metrics - ({{ ansible_default_ipv4.address }})",'
  46. delegate_to: localhost
  47. - name: Replace title in slurm dashboard (2/2)
  48. replace:
  49. path: "{{ role_path }}/files/slurm-dashboard.json"
  50. regexp: '"title": "SLURM - CPUs/GPUs, Nodes, Jobs, Scheduler.*'
  51. replace: '"title": "SLURM - CPUs/GPUs, Nodes, Jobs, Scheduler ({{ ansible_default_ipv4.address }})",'
  52. delegate_to: localhost
  53. - block:
  54. - name: Import Slurm Grafana dashboards
  55. community.grafana.grafana_dashboard:
  56. grafana_url: "http://{{ grafana_svc_ip }}:{{ grafana_svc_port }}"
  57. grafana_user: "{{ hostvars['127.0.0.1']['grafana_username'] }}"
  58. grafana_password: "{{ hostvars['127.0.0.1']['grafana_password'] }}"
  59. state: present
  60. commit_message: Updated by ansible
  61. overwrite: yes
  62. path: "{{ role_path }}/files/{{ item }}"
  63. with_items: "{{ slurm_dashboard_json_files }}"
  64. delegate_to: localhost
  65. no_log: true
  66. register: import_prom_dashboards
  67. rescue:
  68. - name: Import K8s grafana dashboards failed
  69. fail:
  70. msg: "Error: {{ import_prom_dashboards.msg }}"