Skip to content

Use a template for our simplest nginx configs #4231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
fe84990
first draft of simple template for nginx config
acozine Sep 7, 2023
843004a
adds a task to use the templates, with a tag for testing
acozine Sep 7, 2023
68a2fa8
revert this change before merging, for testing only
acozine Sep 7, 2023
3fd7a91
adds comments to vars for clarity
acozine Sep 7, 2023
f7d4c5a
incorporate fix for issue 4090
acozine Sep 20, 2023
c774e32
use 'visibility: public' instead of boolena value for 'public_site'
acozine Sep 20, 2023
90d0a56
adds option to change the load balancing technique
acozine Sep 20, 2023
d1c0087
various improvements, updates example var
acozine Sep 20, 2023
4b032c8
expands list of sites for testing the template
acozine Sep 20, 2023
9967d92
public is a string, not a var
acozine Sep 25, 2023
5e549a5
fix app_protect settings
acozine Sep 25, 2023
93692ad
moar better
acozine Sep 25, 2023
118a32d
add a task to create the cache dirs
acozine Sep 25, 2023
4783e8f
regularize pattern of names
acozine Sep 25, 2023
facf9c9
use pipe instead of colon for task names
acozine Sep 25, 2023
b26941c
include static files from a subdirectory
acozine Oct 2, 2023
6897857
allows us to define specific health check URIs
acozine Oct 5, 2023
98eab7d
oops
acozine Oct 5, 2023
aa33896
set up to test dual-upload (templated and static site configs)
acozine Oct 5, 2023
c0cf8cb
bibdata prod and staging do not use new certs yet
acozine Oct 5, 2023
2e6f8d8
remove static configs that have been templated
acozine Oct 5, 2023
d125111
only remove static site config files, move slash out of var def
acozine Oct 5, 2023
92d786b
define vars in one place, only run cleanup with a tag
acozine Oct 11, 2023
0106636
we are not using streams, leave those vars in defaults/main.yml
acozine Oct 11, 2023
12c5712
update defaults.yml to match, make things tidy
acozine Oct 11, 2023
9b2dbfa
fix whitespace mistake
acozine Oct 11, 2023
e04ecbe
keep active vars in group_vars & unused defaults in role defaults/mai…
acozine Oct 11, 2023
08733d1
we are not using stream config, not sure why these vars were set
acozine Oct 11, 2023
ccba81b
add comments, tidy vars more
acozine Oct 11, 2023
ec630ce
make stream vars parallel with other vars groups
acozine Oct 11, 2023
73a11de
bibdata certs ARE on the LBs
acozine Oct 11, 2023
6aa3c6e
move trickier files to templatize into a static directory
acozine Oct 11, 2023
c793bd0
adds rate limiting option, tidies formatting
acozine Oct 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 23 additions & 157 deletions group_vars/nginxplus/main.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
---
# variables for building nginxplus on our load balancers
deploy_user_uid: 1003
slack_alerts_channel:
- '#infrastructure'
- '#ansible-alerts'
nginx_type: plus
nginx_delete_license: false
# enable rest API
nginx_rest_api_enable: true
nginx_rest_api_write: true
nginx_rest_api_src: api.conf.j2
nginx_rest_api_location: /etc/nginx/conf.d/api.conf
nginx_rest_api_port: 8080
nginx_rest_api_dashboard: true
# modules to install
nginx_modules:
waf: true
geoip: true
Expand All @@ -14,30 +22,31 @@ nginx_modules:
image_filter: true
rtmp: true
xslt: true
nginx_status_enable: false
nginx_status_port: 8080
nginx_rest_api_src: api.conf.j2
nginx_rest_api_location: /etc/nginx/conf.d/api.conf
nginx_rest_api_port: 8080
nginx_rest_api_dashboard: true
nginx_delete_license: false
# the hash table stores server names for fast lookup
# see PR 3578 on princeton_ansible
# increase the size first
# when that stops working, increase the hash buckets
nginx_server_names_hash_bucket_size: 64
nginx_server_names_hash_max_size: 1024
# Upload HTTP NGINX static configuration files.
nginx_http_upload_enable: true
nginx_http_upload_src: conf/http/*.conf
nginx_http_upload_dest: /etc/nginx/conf.d/
nginx_stream_upload_enable: true
nginx_stream_upload_src: conf/stream/*.conf
nginx_stream_upload_dest: /etc/nginx/conf.d/stream/
nginx_http_upload_src: conf/http/static/*.conf
nginx_http_upload_dest: /etc/nginx/conf.d
# Remove previously existing NGINX configuration files.
# Use a list of paths you wish to remove.
nginx_cleanup_config: true
nginx_cleanup_config_path:
- /etc/nginx/conf.d
nginx_cleanup_config_path: "{{nginx_http_upload_dest}}/static/"
# Upload SSL certificates and keys.
nginx_ssl_upload_enable: true
nginx_ssl_crt_upload_src: ssl/*.pem
nginx_ssl_crt_upload_dest: /etc/nginx/conf.d/ssl/certs/
nginx_ssl_key_upload_src: ssl/*.key
nginx_ssl_key_upload_dest: /etc/nginx/conf.d/ssl/private/
# add template files for library production and staging
nginx_template_upload_enable: true
nginx_template_upload_src: conf/http/templates/*.conf
nginx_template_upload_dest: /etc/nginx/conf.d/templates/
# configure datadog log collection
datadog_api_key: "{{vault_datadog_key}}"
datadog_config:
tags: "{{nginxplus_tags}}"
Expand All @@ -64,146 +73,3 @@ datadog_checks:
service: adc
source: adc
sourcecategory: http_web_access
nginx_stream_template_enable: false
nginx_stream_template:
default:
template_file: stream/default.conf.j2
conf_file_name: default.conf
conf_file_location: /etc/nginx/conf.d/stream/
network_streams:
default:
listen_address: localhost
listen_port: 80
udp_enable: false
proxy_pass: backend
proxy_timeout: 3s
proxy_connect_timeout: 1s
proxy_protocol: false
proxy_ssl:
cert: /etc/ssl/certs/proxy_default.crt
key: /etc/ssl/private/proxy_default.key
trusted_cert: /etc/ssl/certs/proxy_ca.crt
server_name: false
name: server_name
protocols: TLSv1 TLSv1.1 TLSv1.2
ciphers: HIGH:!aNULL:!MD5
verify: false
verify_depth: 1
session_reuse: true
health_check_plus: false
upstreams:
upstream1:
name: backend
lb_method: least_conn
zone_name: backend
zone_size: 64k
sticky_cookie: false
servers:
server1:
address: localhost
port: 8080
weight: 1
health_check: max_fails=1 fail_timeout=10s
nginx_http_template_enable: false
nginx_http_template:
default:
template_file: http/default.conf.j2
conf_file_name: default.conf
conf_file_location: /etc/nginx/conf.d/
port: 8081
server_name: localhost
error_page: /usr/share/nginx/html
root: /usr/share/nginx/html
https_redirect: false
autoindex: false
ssl:
cert: /etc/ssl/certs/default.crt
key: /etc/ssl/private/default.key
protocols: TLSv1 TLSv1.1 TLSv1.2
ciphers: HIGH:!aNULL:!MD5
session_cache: none
session_timeout: 5m
web_server:
locations:
default:
location: /home
html_file_location: /usr/share/nginx/html
html_file_name: index.html
autoindex: false
auth_basic: null
auth_basic_file: null
http_demo_conf: false
reverse_proxy:
proxy_cache_path:
- path: /var/cache/nginx/proxy/backend
keys_zone:
name: backend_proxy_cache
size: 10m
levels: "1:2"
max_size: 10g
inactive: 60m
use_temp_path: true
proxy_temp_path:
path: /var/cache/nginx/proxy/temp
proxy_cache_lock: true
proxy_cache_min_uses: 5
proxy_cache_revalidate: true
proxy_cache_use_stale:
- error
- timeout
proxy_ignore_headers:
- Expires
locations:
backend:
location: /
proxy_connect_timeout: null
proxy_pass: http://backend
proxy_read_timeout: null
proxy_ssl:
cert: /etc/ssl/certs/proxy_default.crt
key: /etc/ssl/private/proxy_default.key
trusted_cert: /etc/ssl/certs/proxy_ca.crt
server_name: false
name: server_name
protocols: TLSv1 TLSv1.1 TLSv1.2
ciphers: HIGH:!aNULL:!MD5
verify: false
verify_depth: 1
session_reuse: true
proxy_temp_path:
path: /var/cache/nginx/proxy/backend/temp
proxy_cache_lock: false
proxy_cache_min_uses: 3
proxy_cache_revalidate: false
proxy_cache_use_stale:
- http_403
- http_404
proxy_ignore_headers:
- Vary
- Cache-Control
proxy_redirect: false
websocket: false
auth_basic: null
auth_basic_file: null
health_check_plus: false
proxy_cache:
proxy_cache_path:
path: /var/cache/nginx
keys_zone:
name: one
size: 10m
proxy_temp_path:
path: /var/cache/nginx/proxy
upstreams:
upstream1:
name: backend
lb_method: least_conn
zone_name: backend_mem_zone
zone_size: 64k
sticky_cookie: false
servers:
server1:
address: localhost
port: 8081
weight: 1
health_check: max_fails=1 fail_timeout=10s
29 changes: 0 additions & 29 deletions playbooks/nginxplus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,7 @@
when: ansible_limit is not defined
run_once: true

- name: tell infrastructure and ansible-alerts the playbook is starting
community.general.slack:
token: "{{ vault_tower_slack_token }}"
msg: "Ansible is now running `{{ ansible_play_name }}` with the `{{ ansible_run_tags }}` tag on {{ inventory_hostname }}"
channel: {{ item }}
loop: "{{ slack_alerts_channel }}"
tags: always

# updates existing load balancer
roles:
- role: ../roles/nginxplus

- name: restart nginx with updated loadbalancer configuration
hosts: nginxplus_production
remote_user: pulsys
strategy: linear
become: true

tasks:
- name: nginxplus | restart nginx for realsies
service:
name: nginx
state: restarted
tags: always

post_tasks:
- name: tell everyone on slack you ran an ansible playbook
community.general.slack:
token: "{{ vault_pul_slack_token }}"
msg: "Ansible ran `{{ ansible_play_name }}` on {{ inventory_hostname }}"
channel: {{ item }}
loop: "{{ slack_alerts_channel }}"
tags: always
2 changes: 1 addition & 1 deletion roles/nginxplus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ nginx_main_upload_dest: /etc/nginx/
# Upload HTTP NGINX configuration files.
nginx_http_upload_enable: false
nginx_http_upload_src: conf/http/*.conf
nginx_http_upload_dest: /etc/nginx/conf.d/
nginx_http_upload_dest: /etc/nginx/conf.d
# Upload Stream NGINX configuration files.
nginx_stream_upload_enable: false
nginx_stream_upload_src: conf/stream/*.conf
Expand Down
43 changes: 8 additions & 35 deletions roles/nginxplus/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,44 +95,14 @@ nginx_controller_api_endpoint: null
# Default is false.
nginx_unit_enable: false
nginx_unit_modules: null

# Remove previously existing NGINX configuration files.
# Use a list of paths you wish to remove.
# Default is false.
nginx_cleanup_config: false
nginx_cleanup_config_path:
- /etc/nginx/conf.d

# add template files for library production and staging
nginx_template_upload_enable: false
nginx_template_upload_src: conf/http/templates/*.conf
nginx_template_upload_dest: /etc/nginx/conf.d/templates/
# Enable uploading NGINX configuration files to your system.
# Default for uploading files is false.
# Default location of files is the files folder within the NGINX Ansible role.
# Upload the main NGINX configuration file.
nginx_main_upload_enable: false
nginx_main_upload_src: conf/nginx.conf
nginx_main_upload_dest: /etc/nginx/
# Upload HTTP NGINX configuration files.
nginx_http_upload_enable: false
nginx_http_upload_src: conf/http/*.conf
nginx_http_upload_dest: /etc/nginx/conf.d/
# Upload Stream NGINX configuration files.
nginx_stream_upload_enable: false
nginx_stream_upload_src: conf/stream/*.conf
nginx_stream_upload_dest: /etc/nginx/conf.d/
# Upload HTML files.
nginx_html_upload_enable: false
nginx_html_upload_src: www/*
nginx_html_upload_dest: /usr/share/nginx/html
# Upload SSL certificates and keys.
nginx_ssl_upload_enable: false
nginx_ssl_crt_upload_src: ssl/*.crt
nginx_ssl_crt_upload_dest: /etc/ssl/certs/
nginx_ssl_key_upload_src: ssl/*.key
nginx_ssl_key_upload_dest: /etc/ssl/private/

# Enable creating dynamic templated NGINX HTML demo websites.
nginx_html_demo_template_enable: false
nginx_html_demo_template:
Expand Down Expand Up @@ -397,7 +367,13 @@ nginx_rest_api_dashboard: false
# Enable creating dynamic templated NGINX stream configuration files.
# Defaults will not produce a valid configuration. Instead they are meant to showcase
# the options available for templating. Each key represents a new configuration file.
# Upload Stream NGINX configuration files.
# was set to 'true' in the group_vars for nginxplus
# but we do not have any files in conf/stream/
# nginx_stream_upload_enable: true
nginx_stream_template_enable: false
nginx_stream_upload_src: conf/stream/*.conf
nginx_stream_upload_dest: /etc/nginx/conf.d/stream/
nginx_stream_template:
default:
template_file: stream/default.conf.j2
Expand All @@ -417,6 +393,8 @@ nginx_stream_template:
cert: /etc/ssl/certs/proxy_default.crt
key: /etc/ssl/private/proxy_default.key
trusted_cert: /etc/ssl/certs/proxy_ca.crt
server_name: false
name: server_name
protocols: TLSv1 TLSv1.1 TLSv1.2
ciphers: HIGH:!aNULL:!MD5
verify: false
Expand All @@ -436,8 +414,3 @@ nginx_stream_template:
port: 8080
weight: 1
health_check: max_fails=1 fail_timeout=10s

# manage the hash table that stores server names for fast lookup
# increase the size first, when that stops working, increase the number of hash buckets in the table
nginx_server_names_hash_bucket_size: 64
nginx_server_names_hash_max_size: 1024
57 changes: 0 additions & 57 deletions roles/nginxplus/files/conf/http/abid-staging.conf

This file was deleted.

Loading