Merge pull request #5 from nginxinc/(feature)/refactor-templates

Refactor templates
This commit is contained in:
Alessandro Fael Garcia 2018-02-20 13:35:44 -08:00 committed by GitHub
commit 3a26924618
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 150 additions and 250 deletions

View File

@ -85,60 +85,61 @@ This role has multiple variables. The defaults for all these variables are the f
type: opensource type: opensource
# Specify which branch of Open Source NGINX you want to install. # Specify which branch of Open Source NGINX you want to install.
# Options are 'mainline' or 'stable'. # Options are 'mainline' or 'stable'.
# Default is stable. # Default is mainline.
branch: mainline branch: mainline
# Install nginscript, perl and/or waf modules. # Install nginscript, perl, waf, geoip, image-filter, rtmp and/or xslt modules.
# Default is false. # Default is false.
modules: modules:
njs: false njs: false
perl: false perl: false
waf: false waf: false
geoip: false
image_filter: false
rtmp: false
xslt: false
# Install NGINX Amplify. # Install NGINX Amplify.
# Use your NGINX Amplify API key. # Use your NGINX Amplify API key.
# Default is null. # Default is null.
amplify: null amplify_enable: false
amplify_key: null
# Enable NGINX status data. # Enable NGINX status data.
# Will enable 'stub_status' in open source NGINX and 'status' in NGINX Plus. # Will enable 'stub_status' in open source NGINX and 'status' in NGINX Plus.
# Default is false. # Default is false.
status: false status_enable: false
# Enable NGINX Plus REST API and dashboard. # Enable NGINX Plus REST API and write access.
# Default is false for all three variables. # Default is false.
api: rest_api_enable: false
enable: false rest_api_write: false
write: false # Enable NGINX Plus dashboard. REST API also needs to be enabled.
# Default is false.
dashboard: false dashboard: false
# Location of your NGINX Plus license in your local machine. # Location of your NGINX Plus license in your local machine.
# Default is the files folder within the NGINX Ansible role. # Default is the files folder within the NGINX Ansible role.
license: license:
certificate: license/nginx-repo.crt certificate: license/nginx-repo.crt
key: license/nginx-repo.key key: license/nginx-repo.key
# Location of the configuration files you wish to upload to NGINX. # Enable uploading NGINX configuration files to your system.
# Default is the files folder within the NGINX Ansible role. # Default for uploading files is false.
configuration_files: # Default location of files is the files folder within the NGINX Ansible role.
enable: false main_push_enable: false
main: conf/nginx.conf main_push_location: conf/nginx.conf
http: conf/http/*.conf http_push_enable: false
http_push_location: conf/http/*.conf
stream_push_enable: false
stream_push_location: conf/stream/*.conf
# Configuration variables to create a templated NGINX configuration. # Configuration variables to create a templated NGINX configuration.
# Defaults are the values found in a fresh NGINX installation. # Defaults are the values found in a fresh NGINX installation.
configuration_templates: main_template_enable: false
enable: false main_template_user: nginx
opensource: main_template_worker_processes: auto
user: nginx main_template_error_level: warn
worker_processes: 1 main_template_worker_connections: 1024
error_level: warn main_template_keepalive_timeout: 65
worker_connections: 1024 http_template_enable: false
keepalive_timeout: 65 http_template_listen: 80
listen: 80 http_template_server_name: localhost
server_name: localhost stream_template_enable: false
plus: stream_template_listen: 12345
user: nginx
worker_processes: auto
error_level: notice
worker_connections: 1024
keepalive_timeout: 65
listen: 80
server_name: localhost
Dependencies Dependencies
------------ ------------

View File

@ -5,7 +5,7 @@
type: opensource type: opensource
# Specify which branch of Open Source NGINX you want to install. # Specify which branch of Open Source NGINX you want to install.
# Options are 'mainline' or 'stable'. # Options are 'mainline' or 'stable'.
# Default is stable. # Default is mainline.
branch: mainline branch: mainline
# Install nginscript, perl, waf, geoip, image-filter, rtmp and/or xslt modules. # Install nginscript, perl, waf, geoip, image-filter, rtmp and/or xslt modules.
# Default is false. # Default is false.
@ -20,45 +20,43 @@ modules:
# Install NGINX Amplify. # Install NGINX Amplify.
# Use your NGINX Amplify API key. # Use your NGINX Amplify API key.
# Default is null. # Default is null.
amplify: null amplify_enable: false
amplify_key: null
# Enable NGINX status data. # Enable NGINX status data.
# Will enable 'stub_status' in open source NGINX and 'status' in NGINX Plus. # Will enable 'stub_status' in open source NGINX and 'status' in NGINX Plus.
# Default is false. # Default is false.
status: false status_enable: false
# Enable NGINX Plus REST API and dashboard. # Enable NGINX Plus REST API and write access.
# Default is false for all three variables. # Default is false.
api: rest_api_enable: false
enable: false rest_api_write: false
write: false # Enable NGINX Plus dashboard. REST API also needs to be enabled.
dashboard: false # Default is false.
dashboard: false
# Location of your NGINX Plus license in your local machine. # Location of your NGINX Plus license in your local machine.
# Default is the files folder within the NGINX Ansible role. # Default is the files folder within the NGINX Ansible role.
license: license:
certificate: license/nginx-repo.crt certificate: license/nginx-repo.crt
key: license/nginx-repo.key key: license/nginx-repo.key
# Location of the configuration files you wish to upload to NGINX. # Enable uploading NGINX configuration files to your system.
# Default is the files folder within the NGINX Ansible role. # Default for uploading files is false.
configuration_files: # Default location of files is the files folder within the NGINX Ansible role.
enable: false main_push_enable: false
main: conf/nginx.conf main_push_location: conf/nginx.conf
http: conf/http/*.conf http_push_enable: false
http_push_location: conf/http/*.conf
stream_push_enable: false
stream_push_location: conf/stream/*.conf
# Configuration variables to create a templated NGINX configuration. # Configuration variables to create a templated NGINX configuration.
# Defaults are the values found in a fresh NGINX installation. # Defaults are the values found in a fresh NGINX installation.
configuration_templates: main_template_enable: false
enable: false main_template_user: nginx
opensource: main_template_worker_processes: auto
user: nginx main_template_error_level: warn
worker_processes: 1 main_template_worker_connections: 1024
error_level: warn main_template_keepalive_timeout: 65
worker_connections: 1024 http_template_enable: false
keepalive_timeout: 65 http_template_listen: 80
listen: 80 http_template_server_name: localhost
server_name: localhost stream_template_enable: false
plus: stream_template_listen: 12345
user: nginx
worker_processes: auto
error_level: notice
worker_connections: 1024
keepalive_timeout: 65
listen: 80
server_name: localhost

View File

View File

@ -7,4 +7,4 @@
dest: /tmp/install.sh dest: /tmp/install.sh
- name: "(Install: All NGINX) Install NGINX Amplify" - name: "(Install: All NGINX) Install NGINX Amplify"
shell: API_KEY='{{ amplify }}' sh /tmp/install.sh -y shell: API_KEY='{{ amplify_key }}' sh /tmp/install.sh -y

View File

@ -0,0 +1,25 @@
---
- name: "(Setup: All NGINX) Upload NGINX Main Configuration File"
copy:
src: "{{ main_upload_location }}"
dest: /etc/nginx/nginx.conf
notify: "(Handler: All OSs) Reload NGINX"
when: main_upload_enable
- name: "(Setup: All NGINX) Upload NGINX HTTP Configuration Files"
copy:
src: "{{ item }}"
dest: /etc/nginx/conf.d/
with_fileglob:
- "{{ http_upload_location }}"
notify: "(Handler: All OSs) Reload NGINX"
when: http_upload_enable
- name: "(Setup: All NGINX) Upload NGINX Stream Configuration Files"
copy:
src: "{{ item }}"
dest: /etc/nginx/conf.d/
with_fileglob:
- "{{ stream_upload_location }}"
notify: "(Handler: All OSs) Reload NGINX"
when: stream_upload_enable

View File

@ -1,6 +0,0 @@
---
- name: "(Setup: NGINX Plus) Setup NGINX Plus API"
template:
src: api.j2
dest: /etc/nginx/conf.d/api.conf
notify: "(Handler: All OSs) Reload NGINX"

View File

@ -0,0 +1,6 @@
---
- name: "(Setup: NGINX Plus) Setup NGINX Plus API"
template:
src: api.conf.j2
dest: "{{ (http_template_enable) | ternary('/etc/nginx/conf.d/http/api.conf','/etc/nginx/conf.d/api.conf')}}"
notify: "(Handler: All OSs) Reload NGINX"

View File

@ -0,0 +1,22 @@
---
- name: "(Setup: All NGINX) Dynamically Generate NGINX Main Configuration File"
template:
src: nginx.conf.j2
dest: /etc/nginx/nginx.conf
notify: "(Handler: All OSs) Reload NGINX"
- name: "(Setup: All NGINX) Dynamically Generate NGINX HTTP Configuration Files"
template:
src: "{{ item }}"
dest: /etc/nginx/conf.d/{{ item | basename | regex_replace('\.j2','') }}
with_fileglob:
- "../templates/http/*.j2"
notify: "(Handler: All OSs) Reload NGINX"
- name: "(Setup: All NGINX) Dynamically Generate NGINX Stream Configuration Files"
template:
src: "{{ item }}"
dest: /etc/nginx/conf.d/{{ item | basename | regex_replace('\.j2','') }}
with_fileglob:
- "../templates/stream/*.j2"
notify: "(Handler: All OSs) Reload NGINX"

View File

@ -1,14 +0,0 @@
---
- name: "(Setup: All NGINX) Upload NGINX Main Configuration File"
copy:
src: conf/nginx.conf
dest: /etc/nginx/nginx.conf
notify: "(Handler: All OSs) Reload NGINX"
- name: "(Setup: All NGINX) Upload NGINX HTTP Configuration Files"
copy:
src: "{{ item }}"
dest: /etc/nginx/conf.d/
with_fileglob:
- "conf/http/*.conf"
notify: "(Handler: All OSs) Reload NGINX"

View File

@ -1,32 +0,0 @@
---
- name: "(Setup: Open Source NGINX) Upload Open Source NGINX Main Configuration File"
template:
src: opensource/nginx.conf.j2
dest: /etc/nginx/nginx.conf
when: type == "opensource"
notify: "(Handler: All OSs) Reload NGINX"
- name: "(Setup: Open Source NGINX) Upload Open Source NGINX HTTP Configuration Files"
template:
src: "{{ item }}"
dest: /etc/nginx/conf.d/{{ item | basename | regex_replace('\.j2','') }}
with_fileglob:
- "../templates/opensource/http/*.j2"
when: type == "opensource"
notify: "(Handler: All OSs) Reload NGINX"
- name: "(Setup: NGINX Plus) Upload NGINX Plus Main Configuration File"
template:
src: plus/nginx.conf.j2
dest: /etc/nginx/nginx.conf
when: type == "plus"
notify: "(Handler: All OSs) Reload NGINX"
- name: "(Setup: NGINX Plus) Upload NGINX Plus HTTP Configuration Files"
template:
src: "{{ item }}"
dest: /etc/nginx/conf.d/{{ item | basename | regex_replace('\.j2','') }}
with_fileglob:
- "../templates/plus/http/*.j2"
when: type == "plus"
notify: "(Handler: All OSs) Reload NGINX"

View File

@ -32,17 +32,17 @@
- import_tasks: modules/install-waf.yml - import_tasks: modules/install-waf.yml
when: modules.waf and type == "plus" when: modules.waf and type == "plus"
- import_tasks: conf/upload-files.yml - import_tasks: conf/push-config.yml
when: configuration_files.enable when: main_push_enable or http_push_enable or stream_push_enable
- import_tasks: conf/upload-templates.yml - import_tasks: conf/template-config.yml
when: configuration_templates.enable when: main_template_enable or http_template_enable or stream_template_enable
- import_tasks: conf/setup-status.yml - import_tasks: conf/setup-status.yml
when: status when: status_enable
- import_tasks: conf/setup-api.yml - import_tasks: conf/setup-rest-api.yml
when: api.enable and type == "plus" when: rest_api_enable and type == "plus"
- import_tasks: amplify/install-amplify.yml - import_tasks: amplify/install-amplify.yml
when: amplify is defined and amplify when: amplify_enable and amplify_key is defined and amplify_key

View File

@ -1,13 +1,13 @@
server { server {
listen 8080; listen 8080;
location /api { location /api {
{% if api.write %} {% if rest_api_write %}
api write=on; api write=on;
{% else %} {% else %}
api; api;
{% endif %} {% endif %}
} }
{% if api.dashboard %} {% if dashboard %}
location = /dashboard.html { location = /dashboard.html {
root /usr/share/nginx/html; root /usr/share/nginx/html;
} }

View File

@ -1,6 +1,6 @@
server { server {
listen {{ configuration_templates.opensource.listen }}; listen {{ http_template_listen }};
server_name {{ configuration_templates.opensource.server_name }}; server_name {{ http_template_server_name }};
#charset koi8-r; #charset koi8-r;
#access_log /var/log/nginx/host.access.log main; #access_log /var/log/nginx/host.access.log main;

View File

@ -1,15 +1,15 @@
user {{ configuration_templates.opensource.user }}; user {{ main_template_user }};
worker_processes {{ configuration_templates.opensource.worker_processes }}; worker_processes {{ main_teamplate_worker_processes }};
error_log /var/log/nginx/error.log {{ configuration_templates.opensource.error_level }}; error_log /var/log/nginx/error.log {{ main_template_error_level }};
pid /var/run/nginx.pid; pid /var/run/nginx.pid;
events { events {
worker_connections {{ configuration_templates.opensource.worker_connections }}; worker_connections {{ main_template_worker_connections }};
} }
{% if http_template_enable %}
http { http {
include /etc/nginx/mime.types; include /etc/nginx/mime.types;
default_type application/octet-stream; default_type application/octet-stream;
@ -23,9 +23,16 @@ http {
sendfile on; sendfile on;
#tcp_nopush on; #tcp_nopush on;
keepalive_timeout {{ configuration_templates.opensource.keepalive_timeout }}; keepalive_timeout {{ main_template_keepalive_timeout }};
#gzip on; #gzip on;
include /etc/nginx/conf.d/*.conf; include /etc/nginx/conf.d/http/*.conf;
} }
{% endif %}
{% if stream_template_enable %}
stream {
include /etc/nginx/conf.d/stream/*.conf;
}
{% endif %}

View File

@ -1,60 +0,0 @@
server {
listen {{ configuration_templates.plus.listen }} default_server;
server_name {{ configuration_templates.plus.server_name }};
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
# enable /api/ location with appropriate access control in order
# to make use of NGINX Plus API
#
#location /api/ {
# api write=on;
# allow 127.0.0.1;
# deny all;
#}
# enable NGINX Plus Dashboard; requires /api/ location to be
# enabled and appropriate access control for remote access
#
#location = /dashboard.html {
# root /usr/share/nginx/html;
#}
}

View File

@ -1,50 +0,0 @@
user {{ configuration_templates.plus.user }};
worker_processes {{ configuration_templates.plus.worker_processes }};
error_log /var/log/nginx/error.log {{ configuration_templates.plus.error_level }};
pid /var/run/nginx.pid;
events {
worker_connections {{ configuration_templates.plus.worker_connections }};
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout {{ configuration_templates.plus.keepalive_timeout }};
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
# TCP/UDP proxy and load balancing block
#
#stream {
# Example configuration for TCP load balancing
#upstream stream_backend {
# zone tcp_servers 64k;
# server backend1.example.com:12345;
# server backend2.example.com:12345;
#}
#server {
# listen 12345;
# status_zone tcp_server;
# proxy_pass stream_backend;
#}
#}

View File

@ -0,0 +1,3 @@
server {
listen {{ stream_template_listen }};
}