configure_nginx_prom_grafana.yml 2.5 KB

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