haproxy-wi/app/scripts/ansible/roles/nginx_exporter/tasks/main.yml

156 lines
3.7 KiB
YAML

---
- name: group
become: true
become_user: root
group:
name: "{{ nginx_exporter_group }}"
state: present
system: true
when: nginx_exporter_group_manage | bool
- name: user
become: true
become_user: root
user:
name: "{{ nginx_exporter_user }}"
group: "{{ nginx_exporter_group }}"
home: "{{ nginx_exporter_home }}"
createhome: false
move_home: false
comment: nginx_exporter
state: present
system: true
when: nginx_exporter_user_manage | bool
- name: home
become: true
become_user: root
file:
path: "{{ nginx_exporter_home }}"
owner: "{{ nginx_exporter_user }}"
group: "{{ nginx_exporter_group }}"
mode: "u=rwx,g=rx,o="
state: directory
when: nginx_exporter_home_manage | bool
- name: logs
become: true
become_user: root
file:
path: "{{ nginx_exporter_log_path }}"
owner: "{{ nginx_exporter_user }}"
group: "{{ nginx_exporter_group }}"
mode: "u=rwx,g=rx,o="
state: directory
- name: download tarball
become: true
become_user: root
ignore_errors: yes
get_url:
url: "{{ nginx_exporter_tarball_url }}"
dest: "{{ prometheus_exporter_dist_dir }}/{{ nginx_exporter_signature }}.tar.gz"
owner: root
group: root
mode: "u=rw,go=r"
register: _download_binary
until: _download_binary is succeeded
retries: 5
delay: 2
when: nginx_exporter_version is version('0.9.0', '>=')
- name: download tarball alt
become: true
become_user: root
ignore_errors: yes
get_url:
url: "{{ nginx_exporter_tarball_url_alt }}"
dest: "{{ prometheus_exporter_dist_dir }}/{{ nginx_exporter_signature }}.tar.gz"
owner: root
group: root
register: _download_binary
until: _download_binary is succeeded
retries: 5
delay: 2
mode: "u=rwx,go=rx"
when: nginx_exporter_version is version('0.8.0', '<=')
- name: make distribution directory
become: true
become_user: root
file:
path: "{{ nginx_exporter_dist_dir }}"
owner: root
group: root
mode: "u=rwx,go=rx"
state: directory
when: nginx_exporter_version is version('0.9.0', '>=')
- name: make distribution directory alt
become: true
become_user: root
file:
path: "{{ nginx_exporter_dist_dir_alt }}"
owner: root
group: root
mode: "u=rwx,go=rx"
state: directory
when: nginx_exporter_version is version('0.9.0', '<=')
- name: untar tarball
become: true
become_user: root
unarchive:
src: "{{ prometheus_exporter_dist_dir }}/{{ nginx_exporter_signature }}.tar.gz"
dest: "{{ nginx_exporter_dist_dir }}"
remote_src: true
owner: root
group: root
mode: "u=rwx,go=rx"
creates: "{{ nginx_exporter_dist_dir }}/nginx-prometheus-exporter"
- name: symlink
become: true
become_user: root
file:
src: "{{ nginx_exporter_dist_dir }}/nginx-prometheus-exporter"
path: "{{ prometheus_exporter_dir }}/nginx_exporter"
owner: root
group: root
force: true
state: link
notify: restart nginx_exporter
- name: config
become: true
become_user: root
template:
src: "nginx_exporter.default.conf.j2"
dest: "/etc/default/nginx_exporter"
owner: root
group: root
mode: "u=rw,go=r"
notify: restart nginx_exporter
- name: install service
include_tasks: service-{{ prometheus_exporter_service_mgr }}.yml
- name: Service Enabled
become: true
become_user: root
service:
name: nginx_exporter
enabled: "{{ nginx_exporter_service_enable }}"
use: "{{ prometheus_exporter_service_mgr }}"
when: nginx_exporter_service_manage
- name: Service State
become: true
become_user: root
service:
name: nginx_exporter
state: "{{ nginx_exporter_service_state }}"
use: "{{ prometheus_exporter_service_mgr }}"
register: _nginx_exporter_service_state
when: nginx_exporter_service_manage