Skip to content

add option for custom configs #8

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

Open
wants to merge 49 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
a635f1e
add option for custom configs
pablodav Apr 12, 2019
1513ba1
SSL Nginx server configuration.
Jan 28, 2021
229d58d
Se agregan logs a nginx ssl template.
Jan 29, 2021
2fb337a
Fix log.
Jan 29, 2021
1635bd8
Fix.
Jan 29, 2021
c6114e9
Fix.
Jan 29, 2021
3e78681
Fix.
Jan 29, 2021
6f04a6f
Fix.
Jan 29, 2021
7218557
Fix.
Jan 29, 2021
d4df326
Test.
Jan 29, 2021
1cf8f11
Test.
Jan 29, 2021
3705a91
Fix.
Jan 29, 2021
3f8f760
fix hardcoded paths and readme for ssl
pablodav Feb 4, 2021
1e5f92f
Add location to template ssl in server http.
Feb 5, 2021
368aa22
Test.
Feb 5, 2021
bb9c727
Test.
Feb 5, 2021
95ecf6e
Fix.
Feb 5, 2021
57951ec
Test.
Feb 5, 2021
5731022
Fix.
Feb 5, 2021
16409dc
test
Feb 5, 2021
60a8ca4
Exposed ports added 443.
Feb 5, 2021
85e64a5
Fix.
Feb 5, 2021
12f9580
test.
Feb 5, 2021
e1887b9
Test.
Feb 5, 2021
9618871
Revert.
Feb 5, 2021
af4d72f
Add "include /etc/nginx/mime.types;" to template ssl inside location.
Feb 5, 2021
1c8e95e
Test.
Mar 3, 2021
8cc939c
Test
Mar 3, 2021
52d1aa5
Test.
Mar 3, 2021
6d803cb
Test.
Mar 3, 2021
86c9872
Fix.
Mar 3, 2021
ce98aab
fixes to ssl template
pablodav Mar 4, 2021
e1461d4
missing proxy_pass and other settings on default location
pablodav Mar 4, 2021
c223047
Merge pull request #1 from CoffeeITWorks/ssl_nginx_servers
pablodav Mar 22, 2021
fa14d80
change molecule tests
pablodav Mar 29, 2021
85c67c2
fixes on molecule tests
pablodav Mar 29, 2021
354e848
fixes on molecule tests
pablodav Apr 5, 2021
6da8d45
Update reverse-proxy-ssl.conf.j2
matiasgrana May 26, 2021
9e9b58e
Update reverse-proxy.conf.j2
matiasgrana May 26, 2021
8101560
Update main.yml
matiasgrana May 26, 2021
0546f50
Update reverse-proxy-ssl.conf.j2
matiasgrana May 26, 2021
43993d9
Update reverse-proxy.conf.j2
matiasgrana May 26, 2021
0a38eae
Update reverse-proxy-ssl.conf.j2
matiasgrana May 26, 2021
580bc44
Update main.yml
espinosaemanuele Jul 7, 2024
02cfc40
Add skip ssl verify for https backends
AgustinBentancor Aug 21, 2024
67229d6
Create reverse-proxy-ssl-cloud.conf.j2
matiasgrana Sep 6, 2024
652fcc1
Update main.yml
matiasgrana Sep 6, 2024
d55151c
Create reverse-proxy-ssl-onprem.conf.j2
matiasgrana Sep 6, 2024
b913f8f
Update main.yml
matiasgrana Sep 6, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.molecule
.cache
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ before_install:

install:
- sudo apt-get install -y python-pip libssl-dev libffi-dev
- pip install molecule
- pip install docker-py
- pip install ansible
- pip install "molecule[docker]"
#- ansible-galaxy install -r requirements.yml

script:
Expand Down
33 changes: 33 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
# Based on ansible-lint config
extends: default

rules:
braces:
max-spaces-inside: 1
level: error
brackets:
max-spaces-inside: 1
level: error
colons:
max-spaces-after: -1
level: error
commas:
max-spaces-after: -1
level: error
comments: disable
comments-indentation: disable
document-start: disable
empty-lines:
max: 3
level: error
hyphens:
level: error
indentation: disable
key-duplicates: enable
line-length: disable
new-line-at-end-of-file: disable
new-lines:
type: unix
trailing-spaces: disable
truthy: disable
84 changes: 84 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ Use it in a playbook as follows, assuming you already have docker setup:

```yaml
- hosts: 'servers'

pre_tasks:
- name: Update apt cache.
apt: update_cache=yes cache_valid_time=600
when: ansible_os_family == 'Debian'

roles:
- role: geerlingguy.docker # You can use any other role to install docker, but docker is a requirement (see obove)
- role: 'marvinpinto.docker-nginx'
Expand Down Expand Up @@ -72,6 +78,25 @@ Expected to Be Configured
* `nginx_reverse_proxy_backends`: list of backend servers, including ports and [other valid parameters for `server` in the `upstream` context of an nginx config file](http://nginx.org/en/docs/http/ngx_http_upstream_module.html#server)
* `nginx_reverse_proxy_config_name`: name to use for the proxy file (do not include the '.conf' extension, role will add this)

Custom config files
-------------------

You are able to use the variable `nginx_custom_conf` to setup custom config files in `/etc/nginx/conf.d/configfile.conf`

Example:

```yaml
nginx_custom_conf:
- config_name: some_config # Do not add the .conf, it will be added by the role
# Example lines to add a return to some other url
lines:
- "server {"
- " listen 80;"
- " server_name host.domain.net;"
- " return 301 http://someother:port/path.html;"
- "}"
Comment on lines +90 to +97
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use a dict instead of items ?

nginx_custom_conf:
  - default: |
      server {
        listen: 80;
        ...
      }

Task should be:

- name: deploy custom conf files
  template:
    content: {{ item.value }}
    dest: "{{ nginx_reverse_proxy_config_directory }}/{{ item.key }}.conf"
  with_dict: "{{ nginx_custom_conf }}"

```

Example Playbook
----------------

Expand Down Expand Up @@ -102,6 +127,65 @@ nginx_reverse_proxy_proxies:

```

Example adding ssl reverse proxy support
----------------------------------------

First add a task in your playbook to extract the ssl files

```yaml
- name: Apply tasks for docker nginx servers
hosts: docker_nginx_servers
become: yes
environment: "{{ proxy_env }}"
tasks:
- name: Install Unzip required for unarchive
package:
name: ["unzip","tar"]
state: present
- name: install docker ansible dependencies
pip:
name: docker-py
state: present
- name: Download SSL Certificate bundle
environment:
http_proxy: ''
https_proxy: ''
# Example getting the file from gitlab api
# you can also use unarchive or get_url module
shell: "wget --header='PRIVATE-TOKEN: {{ VAULT_DOCKER_NGINX_SERVERS_VAULT_FILES_TOKEN }}' 'http://exampledomain.com/api/v4/projects/50/repository/files/ssl-certificate.tar.gz/raw?ref=master' -O /tmp/ssl-certificate.tar.gz"
changed_when: False
no_log: True
- name: Unarchive SSL Certificate to ssl folder
unarchive:
src: /tmp/ssl-certificate.tar.gz
dest: /etc/ssl
remote_src: yes
```

```yaml
# Remmember also to modify nginx_exposed_volumes to allow access to the files
nginx_reverse_proxy_proxies_ssl:
- config_name: app2proxy
backend_name: my-backend-2
backends:
- localhost:1882
- localhost:1883 backup # will act as backup, and nginx only passes traffic when primary is unavailable.
domains:
- app2.192.168.88.10.xip.io
balancer_config: least_conn; # Important to add semicolon at the end ; if not the config will break

nginx_reverse_proxy_ssl_crt: '/etc/ssl/exampledomain_com.crt'
nginx_reverse_proxy_ssl_key: '/etc/ssl/exampledomain_com.key'

nginx_exposed_volumes:
- "{{ nginx_base_directory }}/nginx.conf:/etc/nginx/nginx.conf:ro"
- "{{ nginx_base_directory }}/defaults:/usr/share/nginx/html:ro"
- "{{ nginx_reverse_proxy_config_directory }}:/etc/nginx/conf.d:ro"
- "/etc/ssl/exampledomain_com.crt:/etc/ssl/exampledomain_com.crt:ro"
- "/etc/ssl/exampledomain_com.key:/etc/ssl/exampledomain_com.key:ro"

```

License
-------

Expand Down
15 changes: 15 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,31 @@ nginx_static_html_directory: 'defaults'

nginx_reverse_proxy_proxies: []

# Remmember also to modify nginx_exposed_volumes to allow access to the files
nginx_reverse_proxy_proxies_ssl: []
nginx_reverse_proxy_ssl_crt: '/etc/ssl/exampledomain_com.crt'
nginx_reverse_proxy_ssl_key: '/etc/ssl/exampledomain_com.key'

nginx_custom_conf: []

nginx_exposed_ports:
- '80'
- '443'

nginx_published_ports:
- '80:80'
- '443:443'

nginx_exposed_volumes:
- "{{ nginx_base_directory }}/nginx.conf:/etc/nginx/nginx.conf:ro"
- "{{ nginx_base_directory }}/defaults:/usr/share/nginx/html:ro"
- "{{ nginx_reverse_proxy_config_directory }}:/etc/nginx/conf.d:ro"

nginx_reverse_proxy_connect_timeout: '60'
nginx_reverse_proxy_send_timeout: '180'
nginx_reverse_proxy_read_timeout: '300'
nginx_reverse_send_timeout: '180'

nginx_conf: |
user root;
worker_processes 1;
Expand All @@ -40,3 +54,4 @@ nginx_conf: |
keepalive_timeout 65;
include /etc/nginx/conf.d/*.conf;
}

9 changes: 0 additions & 9 deletions molecule/default/Dockerfile.j2

This file was deleted.

6 changes: 4 additions & 2 deletions molecule/default/INSTALL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ Requirements
============

* Docker Engine
* docker-py
* ansible
* molecule[docker]

Install
=======

.. code-block:: bash

$ sudo pip install docker-py
$ pip install --user ansible
$ pip install --user molecule[docker]
23 changes: 23 additions & 0 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
- name: Converge
hosts: all
pre_tasks:
- name: Update apt cache.
apt: update_cache=yes cache_valid_time=600
when: ansible_os_family == 'Debian'

- name: Wait for systemd to complete initialization. # noqa 303
command: systemctl is-system-running
register: systemctl_status
until: >
'running' in systemctl_status.stdout or
'degraded' in systemctl_status.stdout
retries: 30
delay: 5
when: ansible_service_mgr == 'systemd'
changed_when: false
failed_when: systemctl_status.rc > 1

roles:
- role: geerlingguy.docker
- role: ansible-role-docker-nginx
59 changes: 0 additions & 59 deletions molecule/default/create.yml

This file was deleted.

27 changes: 0 additions & 27 deletions molecule/default/destroy.yml

This file was deleted.

Loading