Skip to content

Commit

Permalink
enhancement(node_exporter): use systemd to create node_exporter_textf…
Browse files Browse the repository at this point in the history
…ile_dir if it

doesn't exist
  • Loading branch information
ym committed Mar 23, 2024
1 parent c72059f commit ce68bdb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions roles/node_exporter/tasks/preflight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@
ansible.builtin.package_facts:
when: "not 'packages' in ansible_facts"

- name: Get systemd version
ansible.builtin.command: systemctl --version
changed_when: false
check_mode: false
register: __systemd_version

- name: Set systemd version fact
ansible.builtin.set_fact:
node_exporter_systemd_version: "{{ __systemd_version.stdout_lines[0].split(' ')[1] }}"

- name: Assert that used version supports listen address type
ansible.builtin.assert:
that:
Expand Down
10 changes: 10 additions & 0 deletions roles/node_exporter/templates/node_exporter.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ After=network-online.target
Type=simple
User={{ node_exporter_system_user }}
Group={{ node_exporter_system_group }}
{% if node_exporter_textfile_dir | length > 0 %}
{% if node_exporter_systemd_version | int >= 235 %}
ExecStartPre=+/bin/mkdir -p {{ node_exporter_textfile_dir }}
ExecStartPre=+/bin/chown -R {{ node_exporter_system_user }}:{{ node_exporter_system_group }} {{ node_exporter_textfile_dir }}
{% else %}
ExecStartPre=/bin/mkdir -p {{ node_exporter_textfile_dir }}
ExecStartPre=/bin/chown -R {{ node_exporter_system_user }}:{{ node_exporter_system_group }} {{ node_exporter_textfile_dir }}
PermissionsStartOnly=true
{% endif %}
{% endif %}
ExecStart={{ node_exporter_binary_install_dir }}/node_exporter \
{% for collector in node_exporter_enabled_collectors -%}
{% if not collector is mapping %}
Expand Down

0 comments on commit ce68bdb

Please sign in to comment.