From 6df02004680e41d45b5d7901f44341d0d8030a96 Mon Sep 17 00:00:00 2001 From: Bill ONeill Date: Mon, 21 May 2018 10:13:32 -0400 Subject: [PATCH 1/3] Allow customization of nginx service enablement/status. Default to enabled and started. --- README.md | 5 +++++ defaults/main.yml | 3 +++ tasks/main.yml | 9 +++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 04223bf..0e44ba6 100644 --- a/README.md +++ b/README.md @@ -148,6 +148,11 @@ Configures Nginx's [`log_format`](http://nginx.org/en/docs/http/ngx_http_log_mod (For RedHat/CentOS only) Set this to `false` to disable the installation of the `nginx` yum repository. This could be necessary if you want the default OS stable packages, or if you use Satellite. + nginx_service_state: started + nginx_service_enabled: yes + +The last task in the role configures the current state and the boot time state of the nginx service. Default settings start nginx and set it to startup at boot time. These can be overridden if installing in a container or further control over the service state is needed. + ## Overriding configuration templates If you can't customize via variables because an option isn't exposed, you can override the template used to generate the virtualhost configuration files or the `nginx.conf` file. diff --git a/defaults/main.yml b/defaults/main.yml index 73100c5..1cdef78 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -84,3 +84,6 @@ nginx_log_format: | '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"' + +nginx_service_state: started +nginx_service_enabled: yes diff --git a/tasks/main.yml b/tasks/main.yml index fd523d9..c11a317 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -41,5 +41,10 @@ notify: - reload nginx -- name: Ensure nginx is started and enabled to start at boot. - service: name=nginx state=started enabled=yes +- name: Configure current state of nginx service. + service: name=nginx state={{ nginx_service_state }} + when: ((nginx_service_state is defined) and (nginx_service_state != None)) + +- name: Configure nginx boot enablement. + service: name=nginx enabled={{ nginx_service_enabled }} + when: ((nginx_service_enabled is defined) and (nginx_service_enabled != None)) From 630cf44e8dbae47ef19e940ad1b060222d7abc0b Mon Sep 17 00:00:00 2001 From: Jeff Geerling Date: Thu, 6 Jun 2019 11:24:51 -0500 Subject: [PATCH 2/3] PR #156 follow-up: Make service state more configurable. --- tasks/main.yml | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index c11a317..bfb5fe4 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -41,10 +41,8 @@ notify: - reload nginx -- name: Configure current state of nginx service. - service: name=nginx state={{ nginx_service_state }} - when: ((nginx_service_state is defined) and (nginx_service_state != None)) - -- name: Configure nginx boot enablement. - service: name=nginx enabled={{ nginx_service_enabled }} - when: ((nginx_service_enabled is defined) and (nginx_service_enabled != None)) +- name: Ensure nginx service is running as configured. + service: + name: nginx + state: "{{ nginx_service_state }}" + enabled: "{{ nginx_service_enabled }}" From d2f244b5b6142fc2f873b0d46694fefd2456b7fd Mon Sep 17 00:00:00 2001 From: Jeff Geerling Date: Thu, 6 Jun 2019 11:33:04 -0500 Subject: [PATCH 3/3] PR #156 follow-up: Fix code linting issue. --- README.md | 2 +- defaults/main.yml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0e44ba6..99bc1bd 100644 --- a/README.md +++ b/README.md @@ -151,7 +151,7 @@ Configures Nginx's [`log_format`](http://nginx.org/en/docs/http/ngx_http_log_mod nginx_service_state: started nginx_service_enabled: yes -The last task in the role configures the current state and the boot time state of the nginx service. Default settings start nginx and set it to startup at boot time. These can be overridden if installing in a container or further control over the service state is needed. +By default, this role will ensure Nginx is running and enabled at boot after Nginx is configured. You can use these variables to override this behavior if installing in a container or further control over the service state is required. ## Overriding configuration templates diff --git a/defaults/main.yml b/defaults/main.yml index 1cdef78..d5ac8d3 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -12,6 +12,9 @@ nginx_ppa_version: stable # The name of the nginx package to install. nginx_package_name: "nginx" +nginx_service_state: started +nginx_service_enabled: true + nginx_conf_template: "nginx.conf.j2" nginx_vhost_template: "vhost.j2" @@ -84,6 +87,3 @@ nginx_log_format: | '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"' - -nginx_service_state: started -nginx_service_enabled: yes