diff options
-rw-r--r-- | roles/linux_status/defaults/main.yml | 2 | ||||
-rw-r--r-- | roles/linux_status/handlers/main.yml | 15 | ||||
-rw-r--r-- | roles/linux_status/tasks/main.yml | 34 | ||||
-rw-r--r-- | roles/linux_status/tasks/power_management.yml | 30 |
4 files changed, 53 insertions, 28 deletions
diff --git a/roles/linux_status/defaults/main.yml b/roles/linux_status/defaults/main.yml index 75b3e80..dd7dadc 100644 --- a/roles/linux_status/defaults/main.yml +++ b/roles/linux_status/defaults/main.yml @@ -1 +1 @@ -linux_status_disable_power_management: false +linux_status_enable_power_management: true diff --git a/roles/linux_status/handlers/main.yml b/roles/linux_status/handlers/main.yml index 0ea529f..9c8b019 100644 --- a/roles/linux_status/handlers/main.yml +++ b/roles/linux_status/handlers/main.yml @@ -1,7 +1,18 @@ -- name: Restart linux-status +- name: Collect service facts + ansible.builtin.service_facts: + listen: linux_status_configured + +- name: Reload systemd daemon become: true ansible.builtin.systemd_service: daemon_reload: true + listen: linux_status_configured + +- name: Restart linux-status service + become: true + when: | + 'linux-status.service' in ansible_facts.services and ansible_facts.services['linux-status.service'].state == 'running' + ansible.builtin.systemd_service: name: linux-status state: restarted - listen: linux_status_restart + listen: linux_status_configured diff --git a/roles/linux_status/tasks/main.yml b/roles/linux_status/tasks/main.yml index 951c838..f3344ff 100644 --- a/roles/linux_status/tasks/main.yml +++ b/roles/linux_status/tasks/main.yml @@ -1,31 +1,15 @@ -- name: Disable power management - when: linux_status_disable_power_management - become: true - block: - - name: Create override directory - ansible.builtin.file: - path: /etc/systemd/system/linux-status.service.d - state: directory - owner: root - group: root - mode: '755' - - - name: Create override file - ansible.builtin.template: - src: disable_power_management.conf.j2 - dest: /etc/systemd/system/linux-status.service.d/99-disable_power_management.conf - owner: root - group: root - mode: '644' - notify: linux_status_restart +- name: Configure power management + ansible.builtin.include_tasks: power_management.yml - name: Install linux-status become: true - ansible.builtin.apt: + ansible.builtin.package: name: linux-status state: present - policy_rc_d: 101 - notify: linux_status_restart -- name: Restart systemd service if necessary - ansible.builtin.meta: flush_handlers +- name: Enable & start linux-status.service + become: true + ansible.builtin.systemd_service: + name: linux-status.service + enabled: true + state: started diff --git a/roles/linux_status/tasks/power_management.yml b/roles/linux_status/tasks/power_management.yml new file mode 100644 index 0000000..2288d24 --- /dev/null +++ b/roles/linux_status/tasks/power_management.yml @@ -0,0 +1,30 @@ +- name: Create override directory + become: true + ansible.builtin.file: + path: /etc/systemd/system/linux-status.service.d + state: directory + owner: root + group: root + mode: '755' + +- name: Enable power management + become: true + ansible.builtin.file: + path: /etc/systemd/system/linux-status.service.d/99-disable_power_management.conf + state: absent + when: linux_status_enable_power_management + notify: linux_status_configured + +- name: Disable power management + become: true + ansible.builtin.template: + src: disable_power_management.conf.j2 + dest: /etc/systemd/system/linux-status.service.d/99-disable_power_management.conf + owner: root + group: root + mode: '644' + when: not linux_status_enable_power_management + notify: linux_status_configured + +- name: Restart systemd service if necessary + ansible.builtin.meta: flush_handlers |