You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.6 KiB

  1. ---
  2. - name: Create prometheus user and group
  3. import_tasks: prometheus_user.yml
  4. - name: Check if Prometheus is installed
  5. stat:
  6. path: /opt/prometheus/prometheus
  7. register: prometheus_binary
  8. - name: Download and install Prometheus
  9. when: not prometheus_binary.stat.exists
  10. block:
  11. - name: Download Prometheus from GitHub
  12. get_url:
  13. dest: /tmp/prometheus-{{ prometheus_version }}.tar.gz
  14. url: https://github.com/prometheus/prometheus/releases/download/v{{ prometheus_version }}/prometheus-{{ prometheus_version }}.linux-amd64.tar.gz
  15. checksum: sha256:e12917b25b32980daee0e9cf879d9ec197e2893924bd1574604eb0f550034d46
  16. - name: Create Prometheus directory
  17. file:
  18. path: /opt/prometheus
  19. state: directory
  20. owner: prometheus
  21. group: prometheus
  22. mode: 0755
  23. - name: Extract Prometheus
  24. unarchive:
  25. remote_src: true
  26. src: /tmp/prometheus-{{ prometheus_version }}.tar.gz
  27. dest: /opt/prometheus
  28. owner: prometheus
  29. group: prometheus
  30. extra_opts:
  31. - --strip-components=1
  32. - name: Create Prometheus service file
  33. copy:
  34. src: prometheus.service
  35. dest: /etc/systemd/system/prometheus.service
  36. owner: root
  37. group: root
  38. mode: 0644
  39. - name: Add Prometheus config file
  40. template:
  41. src: prometheus.yml.jinja2
  42. dest: /opt/prometheus/prometheus.yml
  43. owner: prometheus
  44. group: prometheus
  45. mode: 0644
  46. notify:
  47. - Restart prometheus
  48. - name: Start and enable prometheus service
  49. service:
  50. name: prometheus
  51. state: started
  52. enabled: true