Allow customization of nginx service enablement/status. Default to enabled and started.

pull/156/head
Bill ONeill 6 years ago
parent 0010b7e06c
commit 6df0200468
No known key found for this signature in database
GPG Key ID: 9D6382ACBC996EBB
  1. 5
      README.md
  2. 3
      defaults/main.yml
  3. 9
      tasks/main.yml

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

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

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