76 lines
2.4 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
# Тег install можно использовать для выборочного запуска
- name: Create group
ansible.builtin.group:
name: "{{ node_exporter_user }}"
system: yes
state: present
- name: Create user
ansible.builtin.user:
name: "{{ node_exporter_user }}"
group: "{{ node_exporter_group }}"
system: yes
shell: /sbin/nologin
- name: Create installation directory
ansible.builtin.file:
path: "{{ node_exporter_install_dir }}"
state: directory
owner: "{{ node_exporter_user }}"
group: "{{ node_exporter_group }}"
mode: '0755'
- name: Check if node_exporter archive exists locally
ansible.builtin.stat:
path: "/tmp/node_exporter-{{ node_exporter_version }}.linux-amd64.tar.gz"
register: node_archive
- name: Download node_exporter archive if absent
ansible.builtin.get_url:
url: "https://github.com/prometheus/node_exporter/releases/download/v{{ node_exporter_version }}/node_exporter-{{ node_exporter_version }}.linux-amd64.tar.gz"
dest: "/tmp/node_exporter-{{ node_exporter_version }}.linux-amd64.tar.gz"
mode: '0644'
when: not node_archive.stat.exists
changed_when: false
- name: Extract node_exporter binary
ansible.builtin.unarchive:
src: "/tmp/node_exporter-{{ node_exporter_version }}.linux-amd64.tar.gz"
dest: "{{ node_exporter_install_dir }}"
remote_src: yes
extra_opts: [--strip-components=1]
creates: "{{ node_exporter_install_dir }}/node_exporter"
- name: Remove archive after extraction
ansible.builtin.file:
path: "/tmp/node_exporter-{{ node_exporter_version }}.linux-amd64.tar.gz"
state: absent
when: node_archive.stat.exists
changed_when: false
- name: Set binary ownership and permissions
ansible.builtin.file:
path: "{{ node_exporter_install_dir }}/node_exporter"
owner: "{{ node_exporter_user }}"
group: "{{ node_exporter_group }}"
mode: '0755'
- name: Create symlink to node_exporter in /usr/local/bin
ansible.builtin.file:
src: "{{ node_exporter_install_dir }}/node_exporter"
dest: /usr/local/bin/node_exporter
state: link
- name: Deploy systemd unit for node_exporter
ansible.builtin.template:
src: node_exporter.service.j2
dest: "{{ node_exporter_systemd_unit_path }}"
notify: Update Systemd and restart Node Exporter
- name: Enable and start node_exporter service
ansible.builtin.systemd:
name: node_exporter
enabled: yes
state: started