From 2fffbbfd196c31c7be43b049f0fee8b7b72581d4 Mon Sep 17 00:00:00 2001 From: Wojciech Kozlowski Date: Sun, 4 Dec 2022 17:29:43 +0100 Subject: [PATCH] Create system_ups role --- playbooks/00-hosts.yml | 1 - playbooks/tasks/hosts/ups.yml | 29 ------------------- .../roles/system_ups/files}/apcupsd.conf | 0 plays/roles/system_ups/tasks/main.yml | 29 +++++++++++++++++++ plays/system.yml | 4 ++- 5 files changed, 32 insertions(+), 31 deletions(-) delete mode 100644 playbooks/tasks/hosts/ups.yml rename {playbooks/filesystem/yggdrasil/etc/apcupsd => plays/roles/system_ups/files}/apcupsd.conf (100%) create mode 100644 plays/roles/system_ups/tasks/main.yml diff --git a/playbooks/00-hosts.yml b/playbooks/00-hosts.yml index f665c20..9c48465 100644 --- a/playbooks/00-hosts.yml +++ b/playbooks/00-hosts.yml @@ -3,5 +3,4 @@ hosts: yggdrasil tasks: - - import_tasks: tasks/hosts/ups.yml - import_tasks: tasks/hosts/smart.yml diff --git a/playbooks/tasks/hosts/ups.yml b/playbooks/tasks/hosts/ups.yml deleted file mode 100644 index 79ea112..0000000 --- a/playbooks/tasks/hosts/ups.yml +++ /dev/null @@ -1,29 +0,0 @@ -- name: Install acpupsd - apt: - name: apcupsd - -- name: Apcupsd configuration - copy: - src: ./filesystem/{{ ansible_hostname }}/etc/apcupsd/apcupsd.conf - dest: /etc/apcupsd/apcupsd.conf - mode: 0644 - register: apcupsd_conf - -- name: Enable apcupsd - systemd: - name: apcupsd - enabled: yes - -- name: Start apcupsd - systemd: - name: apcupsd - state: started - register: apcupsd_start - -- name: Restart apcupsd - systemd: - name: apcupsd - state: restarted - when: - apcupsd_conf is changed and - apcupsd_start is not changed diff --git a/playbooks/filesystem/yggdrasil/etc/apcupsd/apcupsd.conf b/plays/roles/system_ups/files/apcupsd.conf similarity index 100% rename from playbooks/filesystem/yggdrasil/etc/apcupsd/apcupsd.conf rename to plays/roles/system_ups/files/apcupsd.conf diff --git a/plays/roles/system_ups/tasks/main.yml b/plays/roles/system_ups/tasks/main.yml new file mode 100644 index 0000000..8168fb8 --- /dev/null +++ b/plays/roles/system_ups/tasks/main.yml @@ -0,0 +1,29 @@ +- name: "install acpupsd" + ansible.builtin.apt: + name: "apcupsd" + +- name: "apcupsd configuration" + ansible.builtin.copy: + src: "./apcupsd.conf" + dest: "/etc/apcupsd/apcupsd.conf" + mode: 0644 + register: apcupsd_conf + +- name: "enable apcupsd" + ansible.builtin.systemd: + name: "apcupsd" + enabled: true + +- name: "start apcupsd" + ansible.builtin.systemd: + name: "apcupsd" + state: "started" + register: apcupsd_start + +- name: "restart apcupsd" + ansible.builtin.systemd: + name: "apcupsd" + state: "restarted" + when: + apcupsd_conf is changed and + apcupsd_start is not changed diff --git a/plays/system.yml b/plays/system.yml index 2f82e56..12c8939 100644 --- a/plays/system.yml +++ b/plays/system.yml @@ -1,7 +1,9 @@ --- -- name: "play : system : zfs, smart, ups : yggdrasil" +- name: "play : system : ups, smart, zfs : yggdrasil" hosts: "yggdrasil" roles: + - role: "system_ups" + tags: "role:system_ups" - role: "system_zfs" tags: "role:system_zfs"