refactor ♻️: Refactor task to use template for creating systemd service.
Some checks failed
ansible-lint / Ansible Lint (push) Failing after 10s
Some checks failed
ansible-lint / Ansible Lint (push) Failing after 10s
This commit refactors the existing task to utilize a template for creating systemd services, enhancing modularity and maintainability.
This commit is contained in:
@@ -77,30 +77,13 @@
|
|||||||
# -------------------------
|
# -------------------------
|
||||||
# 4. Create systemd service for persistence
|
# 4. Create systemd service for persistence
|
||||||
# -------------------------
|
# -------------------------
|
||||||
- name: Create systemd service to persist WoL
|
- name: Create systemd service from template
|
||||||
ansible.builtin.copy:
|
ansible.builtin.template:
|
||||||
|
src: wol-interfaces.service.j2
|
||||||
dest: /etc/systemd/system/wol-interfaces.service
|
dest: /etc/systemd/system/wol-interfaces.service
|
||||||
content: |
|
owner: root
|
||||||
[Unit]
|
group: root
|
||||||
Description=Set Wake-on-LAN on network interfaces
|
mode: '0644'
|
||||||
After=network.target
|
|
||||||
Wants=network.target
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
Type=oneshot
|
|
||||||
ExecStart=/bin/bash -c '
|
|
||||||
{% for intf, enabled, supported in en_interfaces | zip(wol_enabled.results, wol_supported.results) %}
|
|
||||||
{% if wol_mode in supported.stdout %}
|
|
||||||
{% if wol_mode not in enabled.stdout %}
|
|
||||||
/sbin/ethtool -s {{ intf }} wol {{ wol_mode }};
|
|
||||||
{% endif %}
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
|
||||||
'
|
|
||||||
RemainAfterExit=yes
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=multi-user.target
|
|
||||||
notify:
|
notify:
|
||||||
- Reload systemd
|
- Reload systemd
|
||||||
|
|
||||||
|
|||||||
13
templates/wol-interfaces.service.j2
Normal file
13
templates/wol-interfaces.service.j2
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Set Wake-on-LAN on network interfaces
|
||||||
|
After=network.target
|
||||||
|
Wants=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
ExecStart=/bin/bash -c '{% for intf, enabled, supported in en_interfaces | zip(wol_enabled.results, wol_supported.results) %}
|
||||||
|
{% if wol_mode in supported.stdout and wol_mode not in enabled.stdout %}/sbin/ethtool -s {{ intf }} wol {{ wol_mode }}; {% endif %}{% endfor %}'
|
||||||
|
RemainAfterExit=yes
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
Reference in New Issue
Block a user