Merge pull request #156 from spreedly/restart_via_handler

Don't start service in tasks. Defer to handlers to allow further configuration outside of role.
This commit is contained in:
Jeff Geerling 2019-06-06 11:45:00 -05:00 committed by GitHub
commit 79650c5886
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 2 deletions

View File

@ -150,6 +150,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
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
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.

View File

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

View File

@ -41,5 +41,8 @@
notify:
- reload nginx
- name: Ensure nginx is started and enabled to start at boot.
service: name=nginx state=started enabled=yes
- name: Ensure nginx service is running as configured.
service:
name: nginx
state: "{{ nginx_service_state }}"
enabled: "{{ nginx_service_enabled }}"