From 81b7a2af3e9bfd6543dbcca3893f06efd5ed6919 Mon Sep 17 00:00:00 2001 From: Andrea Cimbalo Date: Sat, 8 Apr 2017 18:55:03 +0200 Subject: [PATCH] enable service task and handlers to run on openwrt --- handlers/service.yaml | 39 ++++++++++++++++++++++++++++----- tasks/service.yaml | 51 +++++++++++++++++++++++++++++++++---------- 2 files changed, 72 insertions(+), 18 deletions(-) diff --git a/handlers/service.yaml b/handlers/service.yaml index d37de5f..43adbea 100644 --- a/handlers/service.yaml +++ b/handlers/service.yaml @@ -1,9 +1,36 @@ --- - name: restart {{ service_name }} - service: - name: "{{ service_name }}" - state: restarted + debug: msg="notify restart on all os" + changed_when: true + notify: + - restart {{ service_name }} on all distro + - restart {{ service_name }} on openwrt + - name: reload {{ service_name }} - service: - name: "{{ service_name }}" - state: reloaded + debug: msg="notify reload on all os" + changed_when: true + notify: + - reload {{ service_name }} on all distro + - reload {{ service_name }} on openwrt + +- block: + - name: restart {{ service_name }} on all distro + service: + name: "{{ service_name }}" + state: restarted + - name: reload {{ service_name }} on all distro + service: + name: "{{ service_name }}" + state: reloaded + 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' diff --git a/tasks/service.yaml b/tasks/service.yaml index 887c954..0e18f92 100644 --- a/tasks/service.yaml +++ b/tasks/service.yaml @@ -1,13 +1,40 @@ --- -- name: install {{ service_name }} - apt: - name: "{{ item }}" - state: present - update_cache: yes - cache_valid_time: 3600 - install_recommends: '{{ install_recommends | default("no") }}' - with_items: "{{ service_packages }}" -- name: start {{ service_name }} at boot - service: - name: "{{ service_name }}" - enabled: yes +- block: + - name: install {{ service_name }} + apt: + name: "{{ item }}" + state: present + update_cache: yes + cache_valid_time: 3600 + install_recommends: '{{ install_recommends | default("no") }}' + with_items: "{{ service_packages }}" + + - name: start {{ service_name }} at boot + service: + name: "{{ service_name }}" + enabled: yes + when: ansible_distribution != 'openwrt' + +- block: + - name: install {{ service_name }} + opkg: + name: "{{ item }}" + state: present + with_items: "{{ service_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 + 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 + when: ansible_distribution == 'openwrt'