Browse Source

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`.
python3
Zolfa 5 years ago
parent
commit
bfb1ed9edf
Signed by: zolfa GPG Key ID: E1A43B038C4D6616
2 changed files with 25 additions and 22 deletions
  1. +20
    -9
      roles/service/handlers/main.yaml
  2. +5
    -13
      roles/service/tasks/main.yaml

+ 20
- 9
roles/service/handlers/main.yaml View File

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

+ 5
- 13
roles/service/tasks/main.yaml View File

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

Loading…
Cancel
Save