From 65afd10447cd1f72d37a8df38211daa48065f764 Mon Sep 17 00:00:00 2001 From: Paul Belanger Date: Sat, 30 Mar 2019 22:11:31 -0400 Subject: [PATCH] Refactor service logic This allows for more control over the nginx service. Change-Id: I61984c35a5c45ad94d02a12d2fa6fa8a29c81d44 Signed-off-by: Paul Belanger --- defaults/main.yaml | 6 ++++++ handlers/main.yaml | 5 ----- tasks/service.yaml | 22 +++++++++++++++++----- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/defaults/main.yaml b/defaults/main.yaml index 6526ba1..4ab6bc1 100644 --- a/defaults/main.yaml +++ b/defaults/main.yaml @@ -28,3 +28,9 @@ nginx_file_nginx_conf_dest: /etc/nginx/nginx.conf nginx_file_nginx_conf_src: "" nginx_package_name: nginx + +nginx_service_nginx_daemon_reload: true +nginx_service_nginx_enabled: true +nginx_service_nginx_manage: true +nginx_service_nginx_name: nginx +nginx_service_nginx_state: started diff --git a/handlers/main.yaml b/handlers/main.yaml index 85ae008..ca41d99 100644 --- a/handlers/main.yaml +++ b/handlers/main.yaml @@ -12,8 +12,3 @@ # License for the specific language governing permissions and limitations # under the License. --- -- name: Restart nginx - become: yes - service: - name: nginx - state: restarted diff --git a/tasks/service.yaml b/tasks/service.yaml index 01a259b..e9bb610 100644 --- a/tasks/service.yaml +++ b/tasks/service.yaml @@ -14,8 +14,20 @@ --- - name: Enable nginx service become: true - service: - enabled: yes - name: nginx - notify: - - Restart nginx + systemd: + daemon_reload: "{{ nginx_service_nginx_daemon_reload }}" + enabled: "{{ nginx_service_nginx_enabled }}" + name: "{{ nginx_service_nginx_name }}" + register: nginx_service_nginx + when: nginx_service_nginx_manage + +- name: Set nginx service state + become: true + systemd: + daemon_reload: "{{ nginx_service_nginx_daemon_reload }}" + name: "{{ nginx_service_nginx_name }}" + state: "{{ nginx_service_nginx_state }}" + register: nginx_service_nginx_state_info + when: + - nginx_service_nginx_manage + - nginx_service_nginx_state in ['reloaded', 'restarted', 'started', 'stopped']