{{ ansible_managed | comment }}

[Unit]
Description=Prometheus Node Exporter
After=network-online.target

[Service]
Type=simple
User={{ _node_exporter_system_user }}
Group={{ _node_exporter_system_group }}
ExecStart={{ _node_exporter_binary_install_dir }}/node_exporter \
{% for collector in node_exporter_enabled_collectors -%}
{%   if not collector is mapping %}
    --collector.{{ collector }} \
{%   else -%}
{%     set name, options = (collector.items()|list)[0] -%}
    --collector.{{ name }} \
{%     for k,v in options|dictsort %}
    --collector.{{ name }}.{{ k }}={{ v | quote }} \
{%     endfor -%}
{%   endif -%}
{% endfor -%}
{% for collector in node_exporter_disabled_collectors %}
    --no-collector.{{ collector }} \
{% endfor %}
{% if node_exporter_tls_server_config | length > 0 or node_exporter_http_server_config | length > 0 or node_exporter_basic_auth_users | length > 0 %}
    --web.config=/etc/node_exporter/config.yaml \
{% endif %}
    --web.listen-address={{ node_exporter_web_listen_address }} \
    --web.telemetry-path={{ node_exporter_web_telemetry_path }}

SyslogIdentifier=node_exporter
Restart=always
RestartSec=1
StartLimitInterval=0

{% for m in ansible_mounts if m.mount == '/home' %}
ProtectHome=read-only
{% else %}
ProtectHome=yes
{% endfor %}
NoNewPrivileges=yes

{% if node_exporter_systemd_version | int >= 232 %}
ProtectSystem=strict
ProtectControlGroups=true
ProtectKernelModules=true
ProtectKernelTunables=yes
{% else %}
ProtectSystem=full
{% endif %}

[Install]
WantedBy=multi-user.target
