commit f8f91deac156e02b44359276fee8b23d1d262a5a
parent 1704e39513cde82e931623cb33f6a375da4440a7
Author: Leah (ctucx) <leah@ctu.cx>
Date: Mon, 22 Feb 2021 17:03:12 +0100
parent 1704e39513cde82e931623cb33f6a375da4440a7
Author: Leah (ctucx) <leah@ctu.cx>
Date: Mon, 22 Feb 2021 17:03:12 +0100
roles/hostapd: split tasks into multiple files
6 files changed, 111 insertions(+), 109 deletions(-)
M
|
123
+++++++++----------------------------------------------------------------------
diff --git a/roles/hostapd/handlers/main.yml b/roles/hostapd/handlers/main.yml @@ -0,0 +1,17 @@ +--- + +- name: "[OpenRC] Restart service: hostapd (to deploy config changes)" + service: + name: hostapd + state: restarted + when: + - ansible_service_mgr == "openrc" + listen: "Restart hostapd" + +- name: "[systemd] Restart service: hostapd (to deploy config changes)" + systemd: + name: hostapd + state: restarted + when: + - ansible_service_mgr == "systemd" + listen: "Restart hostapd"
diff --git a/roles/hostapd/tasks/configure.yml b/roles/hostapd/tasks/configure.yml @@ -0,0 +1,7 @@ +--- + +- name: "Create file: /etc/hostapd/hostapd.conf" + template: + src: hostapd.conf.j2 + dest: /etc/hostapd/hostapd.conf + notify: Restart hostapd+ \ No newline at end of file
diff --git a/roles/hostapd/tasks/install.yml b/roles/hostapd/tasks/install.yml @@ -0,0 +1,15 @@ +--- + +- name: "[Alpine] Install package: hostapd" + apk: + name: hostapd + state: present + when: + - ansible_distribution == "Alpine" + +- name: "[Archlinux] Install package: hostapd" + pacman: + name: hostapd + state: present + when: + - ansible_distribution == "Archlinux" + \ No newline at end of file
diff --git a/roles/hostapd/tasks/main.yml b/roles/hostapd/tasks/main.yml @@ -1,119 +1,24 @@ --- -# install it -- name: "[Alpine] Install package: hostapd" - apk: - name: hostapd - state: present - update_cache: yes - when: - - ansible_distribution == "Alpine" +- include: install.yml + when: + - services.hostapd.enable is defined - services.hostapd.enable is true -- name: "[Archlinux] Install package: hostapd" - pacman: - name: hostapd - state: present - update_cache: yes - when: - - ansible_distribution == "Archlinux" +- include: configure.yml + when: + - services.hostapd.enable is defined - services.hostapd.enable is true - -# configure it - -- name: "Create file: /etc/hostapd/hostapd.conf" - template: - src: hostapd.conf.j2 - dest: /etc/hostapd/hostapd.conf - register: createConfig - when: - - services.hostapd.enable is true - - -#todo: fix systemd service to wait for device - -# (re)start it - -- name: "[OpenRC] Enable and start service: hostapd" - service: - name: hostapd - enabled: yes - state: started - when: - - ansible_service_mgr == "openrc" - - services.hostapd.enable is true - -- name: "[systemd] Enable and start service: hostapd" - systemd: - name: hostapd - enabled: yes - state: started - when: - - ansible_service_mgr == "systemd" - - services.hostapd.enable is true - -- name: "[OpenRC] Restart service: hostapd" - service: - name: hostapd - state: restarted - when: - - ansible_service_mgr == "openrc" - - services.hostapd.enable is true - - createConfig.changed - -- name: "[systemd] Restart service: hostapd" - systemd: - name: hostapd - state: restarted - when: - - ansible_service_mgr == "systemd" +- include: start.yml + when: + - services.hostapd.enable is defined - services.hostapd.enable is true - - createConfig.changed - - -# stop it - -- name: "[OpenRC] Disable and stop service: hostapd" - service: - name: hostapd - enabled: no - state: stopped - when: - - ansible_service_mgr == "openrc" - - services.hostapd.enable is false - -- name: "[systemd] Disable and stop service: hostapd" - systemd: - name: hostapd - enabled: no - state: stopped - when: - - ansible_service_mgr == "systemd" - - services.hostapd.enable is false - - -# remove it -- name: "[Alpine] Remove package: hostapd" - apk: - name: hostapd - state: absent - when: - - ansible_distribution == "Alpine" - - services.hostapd.enable is false - -- name: "[Archlinux] Remove package: hostapd" - pacman: - name: hostapd - state: absent - when: - - ansible_distribution == "Archlinux" - - services.hostapd.enable is false +- name: Run handlers + meta: flush_handlers -- name: "Remove directory: /etc/hostapd" - file: - path: /etc/hostapd - state: absent - when: +- include: remove.yml + when: + - services.hostapd.enable is defined - services.hostapd.enable is false
diff --git a/roles/hostapd/tasks/remove.yml b/roles/hostapd/tasks/remove.yml @@ -0,0 +1,38 @@ +--- + +- name: "[OpenRC] Disable and stop service: hostapd" + service: + name: hostapd + enabled: no + state: stopped + when: + - ansible_service_mgr == "openrc" + +- name: "[systemd] Disable and stop service: hostapd" + systemd: + name: hostapd + enabled: no + state: stopped + when: + - ansible_service_mgr == "systemd" + + +- name: "[Alpine] Remove package: hostapd" + apk: + name: hostapd + state: absent + when: + - ansible_distribution == "Alpine" + +- name: "[Archlinux] Remove package: hostapd" + pacman: + name: hostapd + state: absent + when: + - ansible_distribution == "Archlinux" + + +- name: "Remove directory: /etc/hostapd" + file: + path: /etc/hostapd + state: absent
diff --git a/roles/hostapd/tasks/start.yml b/roles/hostapd/tasks/start.yml @@ -0,0 +1,18 @@ +--- + +- name: "[OpenRC] Enable and start service: hostapd" + service: + name: hostapd + enabled: yes + state: started + when: + - ansible_service_mgr == "openrc" + +- name: "[systemd] Enable and start service: hostapd" + systemd: + name: hostapd + enabled: yes + state: started + when: + - ansible_service_mgr == "systemd" +