Browse Source

enable service task and handlers to run on openwrt

python3
Andrea Cimbalo 8 years ago
parent
commit
81b7a2af3e
2 changed files with 72 additions and 18 deletions
  1. +33
    -6
      handlers/service.yaml
  2. +39
    -12
      tasks/service.yaml

+ 33
- 6
handlers/service.yaml View File

@ -1,9 +1,36 @@
--- ---
- name: restart {{ service_name }} - 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 }} - 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'

+ 39
- 12
tasks/service.yaml View File

@ -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'

Loading…
Cancel
Save