From bfb1ed9edf08d988a9cf8d392041a341cbf275d3 Mon Sep 17 00:00:00 2001 From: Zolfa Date: Tue, 28 Apr 2020 21:51:33 +0200 Subject: [PATCH] roles/service: migrate to openwrt-init Use openwrt-init module instead of command when possible. Keep fix for `ssh` service that in OpenWRT is still called `sshd` while in Debian is `ssh`. --- roles/service/handlers/main.yaml | 29 ++++++++++++++++++++--------- roles/service/tasks/main.yaml | 18 +++++------------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/roles/service/handlers/main.yaml b/roles/service/handlers/main.yaml index 0ffa2ec..e3ef1cc 100644 --- a/roles/service/handlers/main.yaml +++ b/roles/service/handlers/main.yaml @@ -25,12 +25,23 @@ when: ansible_distribution != 'openwrt' - block: -# waithing for ansible 2.3 (https://docs.ansible.com/ansible/openwrt_init_module.html) -# - openwrt_init: -# name: "{{ service_name }}" -# state: reloaded - - name: restart {{ service_name }} on openwrt - shell: "/etc/init.d/{{ service_name }} restart" - - name: reload {{ service_name }} on openwrt - shell: /etc/init.d/"{{ service_name }} reload" - when: ansible_distribution == 'openwrt' + - name: 'restart {{ service_name }} on openwrt' + openwrt_init: + name: '{{ service_name }}' + state: 'restarted' + - name: 'reload {{ service_name }} on openwrt' + openwrt_init: + name: '{{ service_name }}' + state: 'reloaded' + when: (ansible_distribution == 'openwrt') and (service_name != 'ssh') + +- block: + - name: 'restart {{ service_name }} on openwrt' + openwrt_init: + name: 'sshd' + state: 'restarted' + - name: 'reload {{ service_name }} on openwrt' + openwrt_init: + name: 'sshd' + state: 'reloaded' + when: (ansible_distribution == 'openwrt') and (service_name == 'ssh') diff --git a/roles/service/tasks/main.yaml b/roles/service/tasks/main.yaml index e9c89c5..548393a 100644 --- a/roles/service/tasks/main.yaml +++ b/roles/service/tasks/main.yaml @@ -25,19 +25,11 @@ tags: - 'packages' -# remove this in ansible 2.3 (see next comment) - - name: link /etc/init.d/sshd init script to /etc/init.d/ssh - file: - src: "/etc/init.d/sshd" - dest: "/etc/init.d/ssh" - state: link + - set_fact: + service_name: 'sshd' when: service_name == 'ssh' -# waithing for ansible 2.3 (https://docs.ansible.com/ansible/openwrt_init_module.html) -# - openwrt_init: -# name: "{{ service_name }}" -# enabled: yes - - name: start {{ service_name }} at boot - shell: "/etc/init.d/{{ service_name }} enable" - changed_when: false + - openwrt_init: + name: '{{ service_name }}' + enabled: true when: ansible_distribution == 'openwrt'