configure_nginx_prom_grafana.yml 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # Copyright 2021 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 control_plane_monitoring variables
  16. include_vars: "{{ role_path }}/../../control_plane/roles/control_plane_monitoring/vars/main.yml"
  17. - name: Install Nginx
  18. package:
  19. name: nginx
  20. state: present
  21. when: ansible_facts['distribution'] != opensuse_os_name
  22. - name: Install Nginx
  23. zypper:
  24. name: nginx
  25. state: present
  26. when: ansible_facts['distribution'] == opensuse_os_name
  27. - name: Start and enable nginx service
  28. service:
  29. name: nginx
  30. state: restarted
  31. enabled: yes
  32. - name: Get prometheus service IP
  33. command: kubectl get svc -l app=prometheus,component=server -o=jsonpath='{.items[0].spec.clusterIP}'
  34. changed_when: false
  35. register: prometheus_svc_ip
  36. - name: Configure nginx.conf (1/2)
  37. replace:
  38. path: "{{ role_path }}/templates/nginx.conf.j2"
  39. regexp: ' server_name .*'
  40. replace: " server_name {{ ansible_default_ipv4.address }};"
  41. delegate_to: localhost
  42. - name: Configure nginx.conf (2/2)
  43. replace:
  44. path: "{{ role_path }}/templates/nginx.conf.j2"
  45. regexp: ' proxy_pass http://.*'
  46. replace: " proxy_pass http://{{ prometheus_svc_ip.stdout }};"
  47. delegate_to: localhost
  48. - name: Load nginx conf
  49. template:
  50. src: nginx.conf.j2
  51. dest: "{{ nginx_conf_file_path }}"
  52. mode: "{{ nginx_conf_file_mode }}"
  53. - name: Validate nginx conf file
  54. command: nginx -t
  55. changed_when: false
  56. - name: Start and enable nginx service
  57. service:
  58. name: nginx
  59. state: restarted
  60. enabled: yes
  61. - name: Create prometheus datasource in grafana
  62. community.grafana.grafana_datasource:
  63. name: "hpc-prometheus-{{ ansible_default_ipv4.address }}"
  64. grafana_url: "http://{{ grafana_svc_ip }}:{{ grafana_svc_port }}"
  65. grafana_user: "{{ grafana_username }}"
  66. grafana_password: "{{ grafana_password }}"
  67. ds_type: prometheus
  68. ds_url: "http://{{ ansible_default_ipv4.address }}"
  69. access: direct
  70. delegate_to: localhost
  71. no_log: true