download.yml 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. ---
  2. - name: Get systemd version
  3. command: systemctl --version
  4. changed_when: false
  5. check_mode: false
  6. register: __systemd_version
  7. tags:
  8. - skip_ansible_lint
  9. - name: Set systemd version fact
  10. set_fact:
  11. prometheus_systemd_version: "{{ __systemd_version.stdout_lines[0].split(' ')[-1] }}"
  12. - name: Assert no duplicate config flags
  13. assert:
  14. that:
  15. - prometheus_config_flags_extra['config.file'] is not defined
  16. - prometheus_config_flags_extra['storage.tsdb.path'] is not defined
  17. - prometheus_config_flags_extra['storage.local.path'] is not defined
  18. - prometheus_config_flags_extra['web.listen-address'] is not defined
  19. - prometheus_config_flags_extra['web.external-url'] is not defined
  20. msg: "Detected duplicate configuration entry. Please check your ansible variables and role README.md."
  21. - name: Assert external_labels aren't configured twice
  22. assert:
  23. that: prometheus_global.external_labels is not defined
  24. msg: "Use prometheus_external_labels to define external labels"
  25. - name: Set prometheus external metrics path
  26. set_fact:
  27. prometheus_metrics_path: "/{{ ( prometheus_web_external_url + '/metrics' ) | regex_replace('^(.*://)?(.*?)/') }}"
  28. - name: Fail when prometheus_config_flags_extra duplicates parameters set by other variables
  29. fail:
  30. msg: >
  31. Whooops. You are duplicating configuration. Please look at your prometheus_config_flags_extra
  32. and check against other variables in defaults/main.yml
  33. with_items:
  34. - 'storage.tsdb.retention'
  35. - 'storage.tsdb.path'
  36. - 'storage.local.retention'
  37. - 'storage.local.path'
  38. - 'config.file'
  39. - 'web.listen-address'
  40. - 'web.external-url'
  41. when: item in prometheus_config_flags_extra.keys()
  42. - name: Get all file_sd files from scrape_configs
  43. set_fact:
  44. file_sd_files: "{{ prometheus_scrape_configs | json_query('[*][].file_sd_configs[*][].files[]') }}"
  45. - name: Fail when file_sd targets are not defined in scrape_configs
  46. fail:
  47. msg: >
  48. Oh, snap! `{{ item.key }}` couldn't be found in your scrape configs. Please ensure you provided
  49. all targets from prometheus_targets in prometheus_scrape_configs
  50. when: not prometheus_config_dir + "/file_sd/" + item.key + ".yml" in file_sd_files
  51. # when: not item | basename | splitext | difference(['.yml']) | join('') in prometheus_targets.keys()
  52. with_dict: "{{ prometheus_targets }}"
  53. - name: Alert when prometheus_alertmanager_config is empty, but prometheus_alert_rules is specified
  54. debug:
  55. msg: >
  56. No alertmanager configuration was specified. If you want your alerts to be sent make sure to
  57. specify a prometheus_alertmanager_config in defaults/main.yml.
  58. when:
  59. - prometheus_alertmanager_config == []
  60. - prometheus_alert_rules != []
  61. - name: Download... Download Prometheus archive
  62. get_url:
  63. url: "{{ prometheus_url }}/{{ prometheus_tarball }}.tar.gz"
  64. dest: /tmp/{{ prometheus_tarball }}.tar.gz
  65. checksum: "sha256:{{ prometheus_url }}/sha256sums.txt"
  66. register: _download_archive
  67. until: _download_archive is succeeded
  68. retries: 5
  69. delay: 2
  70. when: not prometheus_skip_install
  71. - name: unpack prometheus binaries
  72. unarchive:
  73. src: "/tmp/{{ prometheus_tarball }}.tar.gz"
  74. dest: "/tmp"
  75. creates: "/tmp/{{ prometheus_tarball }}/prometheus"
  76. remote_src: true
  77. when: not prometheus_skip_install