From d79aef473f6e68eaf32181ccb20d2aa78ee0d905 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Thu, 8 Aug 2019 22:52:37 +0200 Subject: [PATCH] add service state variables --- defaults/main.yml | 3 ++ handlers/main.yml | 2 +- molecule/ec2-centos-7/playbook.yml | 2 ++ tasks/install.yml | 58 ++++-------------------------- tasks/post_tasks.yml | 18 ++++------ 5 files changed, 18 insertions(+), 65 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 08eff21..5878319 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -7,6 +7,9 @@ zigbee2mqtt_secondary_groups: - tty - dialout +zigbee2mqtt_service_state: started +zigbee2mqtt_service_restart_state: restarted + zigbee2mqtt_base_dir: /opt/zigbee2mqtt zigbee2mqtt_log_dir: "{{ zigbee2mqtt_base_dir }}/log" zigbee2mqtt_log_level: info diff --git a/handlers/main.yml b/handlers/main.yml index 4b6e2df..0ca5823 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,7 +1,7 @@ --- - name: Restart zigbee2mqtt service systemd: - state: restarted + state: "{{ zigbee2mqtt_service_restart_state }}" daemon_reload: yes name: zigbee2mqtt listen: __zigbee2mqtt_restart diff --git a/molecule/ec2-centos-7/playbook.yml b/molecule/ec2-centos-7/playbook.yml index 295b5ca..b5cf6fe 100644 --- a/molecule/ec2-centos-7/playbook.yml +++ b/molecule/ec2-centos-7/playbook.yml @@ -5,6 +5,8 @@ mosquitto_packages_extra: - epel-release mosquitto_bind_address: "127.0.0.1" + zigbee2mqtt_service_state: stopped + zigbee2mqtt_service_restart_state: stopped roles: - role: xoxys.mosquitto diff --git a/tasks/install.yml b/tasks/install.yml index 1a024d9..83d0945 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -14,35 +14,6 @@ become_user: root - block: - # - name: Check data dir - # stat: - # path: "{{ zigbee2mqtt_base_dir }}/data" - # register: __zigbee_datadir - - # - name: Backup data directory - # synchronize: - # src: "{{ zigbee2mqtt_base_dir }}/data/" - # dest: "/tmp/zigbee_data" - # recursive: yes - # delegate_to: "{{ inventory_hostname }}" - # when: __zigbee_datadir.stat.exists - - # - name: Setup zigbee2mqtt - # git: - # repo: "https://github.com/Koenkk/zigbee2mqtt" - # dest: "{{ zigbee2mqtt_base_dir }}/bin" - # version: "{{ zigbee2mqtt_version }}" - # force: yes - # register: __zigbee2mqtt_install - - # - name: Restore data directory - # synchronize: - # src: "/tmp/zigbee_data/" - # dest: "{{ zigbee2mqtt_base_dir }}/data" - # recursive: yes - # delegate_to: "{{ inventory_hostname }}" - # when: __zigbee_datadir.stat.exists - - name: Download release 'v{{ zigbee2mqtt_version }}' unarchive: src: "https://github.com/Koenkk/zigbee2mqtt/archive/{{ zigbee2mqtt_version }}.tar.gz" @@ -52,8 +23,6 @@ extra_opts: - --strip-components=1 - register: __zigbee2mqtt_install - - name: Delete existing node_modules folder file: path: "{{ zigbee2mqtt_base_dir }}/node_modules" @@ -69,27 +38,12 @@ become: True become_user: "{{ zigbee2mqtt_user }}" -- block: - # - name: Cleanup base directory - # file: - # path: "{{ zigbee2mqtt_base_dir }}/{{ item }}" - # state: absent - # loop: - # - docker - # - docs - # - images - # - LICENSE - # - README.md - # - scripts - # - test - # - update.sh - - - name: Deploy configuration file - template: - src: "zigbee2mqtt/data/configuration.yaml.j2" - dest: "{{ zigbee2mqtt_base_dir }}/data/configuration.yaml" - mode: 0600 - notify: __zigbee2mqtt_restart +- name: Deploy configuration file + template: + src: "zigbee2mqtt/data/configuration.yaml.j2" + dest: "{{ zigbee2mqtt_base_dir }}/data/configuration.yaml" + mode: 0600 + notify: __zigbee2mqtt_restart become: True become_user: "{{ zigbee2mqtt_user }}" diff --git a/tasks/post_tasks.yml b/tasks/post_tasks.yml index d323801..0d2a66b 100644 --- a/tasks/post_tasks.yml +++ b/tasks/post_tasks.yml @@ -1,15 +1,9 @@ --- -- block: - - name: Ensure zigbee2mqtt service is up and running - systemd: - state: started - daemon_reload: yes - enabled: yes - name: zigbee2mqtt - - # - name: Delete backup data directory - # file: - # path: "/tmp/zigbee_data" - # state: absent +- name: Ensure zigbee2mqtt service is up and running + systemd: + state: "{{ zigbee2mqtt_service_state }}" + daemon_reload: yes + enabled: yes + name: zigbee2mqtt become: True become_user: root