mirror of
https://github.com/prometheus-community/ansible
synced 2025-02-16 20:58:26 +00:00
fix(node_exporter): Fix ProtectHome for textfiles (#184)
Set the node_exporter `ProtectHome=read-only` when the textfile dir is in `/home`. Fixes: https://github.com/prometheus-community/ansible/issues/183 Signed-off-by: SuperQ <superq@gmail.com>
This commit is contained in:
parent
b44af63d31
commit
d7ad271617
3 changed files with 15 additions and 1 deletions
|
@ -4,3 +4,4 @@ provisioner:
|
||||||
group_vars:
|
group_vars:
|
||||||
all:
|
all:
|
||||||
node_exporter_version: latest
|
node_exporter_version: latest
|
||||||
|
node_exporter_textfile_dir: /home/node_exporter
|
||||||
|
|
|
@ -19,6 +19,16 @@ def test_files(host, files):
|
||||||
assert f.is_file
|
assert f.is_file
|
||||||
|
|
||||||
|
|
||||||
|
def test_directories(host):
|
||||||
|
dirs = [
|
||||||
|
"/home/node_exporter"
|
||||||
|
]
|
||||||
|
for dir in dirs:
|
||||||
|
d = host.file(dir)
|
||||||
|
assert d.is_directory
|
||||||
|
assert d.exists
|
||||||
|
|
||||||
|
|
||||||
def test_service(host):
|
def test_service(host):
|
||||||
s = host.service("node_exporter")
|
s = host.service("node_exporter")
|
||||||
try:
|
try:
|
||||||
|
@ -35,7 +45,7 @@ def test_service(host):
|
||||||
def test_protecthome_property(host):
|
def test_protecthome_property(host):
|
||||||
s = host.service("node_exporter")
|
s = host.service("node_exporter")
|
||||||
p = s.systemd_properties
|
p = s.systemd_properties
|
||||||
assert p.get("ProtectHome") == "yes"
|
assert p.get("ProtectHome") == "read-only"
|
||||||
|
|
||||||
|
|
||||||
def test_socket(host):
|
def test_socket(host):
|
|
@ -42,6 +42,9 @@ StartLimitInterval=0
|
||||||
{% for m in ansible_mounts if m.mount.startswith('/home') %}
|
{% for m in ansible_mounts if m.mount.startswith('/home') %}
|
||||||
{% set ns.protect_home = 'read-only' %}
|
{% set ns.protect_home = 'read-only' %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
{% if node_exporter_textfile_dir.startswith('/home') %}
|
||||||
|
{% set ns.protect_home = 'read-only' %}
|
||||||
|
{% endif %}
|
||||||
ProtectHome={{ ns.protect_home }}
|
ProtectHome={{ ns.protect_home }}
|
||||||
NoNewPrivileges=yes
|
NoNewPrivileges=yes
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue