Skip to content

Commit 1bc19af

Browse files
committed
feat(ipmi-exporter): add option to run ipmi-exporter with sudo
1 parent 357dd8e commit 1bc19af

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

roles/ipmi_exporter/defaults/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,6 @@ ipmi_exporter_config_dir: /etc/ipmi_exporter
3030

3131
# Local path to stash the archive and its extraction
3232
ipmi_exporter_local_cache_path: "/tmp/ipmi_exporter-{{ ansible_facts['system'] | lower }}-{{ _ipmi_exporter_go_ansible_arch }}/{{ ipmi_exporter_version }}"
33+
34+
ipmi_exporter_run_with_sudo: true
35+
ipmi_exporter_sudoers_name: "99-ipmi-exporter"

roles/ipmi_exporter/tasks/configure.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,10 @@
3030
- ipmi_exporter
3131
- configure
3232
- ipmi_exporter_configure
33+
34+
- name: Create the sudoers file to run ipmi commands
35+
community.general.sudoers:
36+
name: "{{ ipmi_exporter_sudoers_name }}"
37+
user: "{{ ipmi_exporter_system_user }}"
38+
commands: "{{ _ipmi_exporter_sudo_commands }}"
39+
when: ipmi_exporter_run_with_sudo

roles/ipmi_exporter/templates/ipmi_exporter.service.j2

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,18 @@ RestartSec=1
2323
StartLimitInterval=0
2424

2525
ProtectHome=yes
26+
27+
{% if ipmi_exporter_run_with_sudo %}
2628
NoNewPrivileges=yes
29+
{% endif %}
2730

2831
{% if (ansible_facts.packages.systemd | first).version is version('232', '>=') %}
2932
ProtectSystem=strict
3033
ProtectControlGroups=true
34+
{% if ipmi_exporter_run_with_sudo %}
3135
ProtectKernelModules=true
3236
ProtectKernelTunables=yes
37+
{% endif %}
3338
PrivateTmp=true
3439
{% else %}
3540
ProtectSystem=full

roles/ipmi_exporter/vars/main.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,11 @@ _ipmi_exporter_binaries: ['ipmi_exporter']
1010
_ipmi_exporter_dependencies: "{{ (ansible_facts['pkg_mgr'] == 'apt')
1111
| ternary((['python-apt'] if ansible_facts['python_version'] is version('3', '<') else ['python3-apt']),
1212
[]) + ['freeipmi'] }}"
13+
_ipmi_exporter_sudo_commands:
14+
- /usr/sbin/ipmimonitoring
15+
- /usr/sbin/ipmi-sensors
16+
- /usr/sbin/ipmi-dcmi
17+
- /usr/sbin/ipmi-raw
18+
- /usr/sbin/bmc-info
19+
- /usr/sbin/ipmi-chassis
20+
- /usr/sbin/ipmi-sel

0 commit comments

Comments
 (0)