2021-04-26 20:35:59 +00:00
|
|
|
- name: ensure directories exist
|
|
|
|
file:
|
|
|
|
path: "{{ item }}"
|
|
|
|
state: directory
|
|
|
|
mode: '0755'
|
|
|
|
loop:
|
|
|
|
- "{{ nginx_confd_folder }}"
|
2021-04-27 17:13:35 +00:00
|
|
|
- name: generate certificates
|
|
|
|
command: openssl req \
|
|
|
|
-x509 \
|
|
|
|
-sha256 \
|
|
|
|
-newkey rsa:2048 \
|
|
|
|
-keyout "{{ data_folder }}/nginx/{{ base_domain }}".key \
|
|
|
|
-subj "/C=CZ/L=Prague/CN=*.{{ base_domain }}/emailAddress={{ admin_email }}"
|
|
|
|
-out "{{ data_folder }}/nginx/{{ base_domain }}".crt \
|
|
|
|
-days 3650 \
|
|
|
|
-nodes \
|
2021-04-26 21:54:10 +00:00
|
|
|
- name: copy certificates
|
|
|
|
copy:
|
|
|
|
src: "{{ item }}"
|
|
|
|
dest: "{{ data_folder }}/nginx"
|
|
|
|
loop:
|
2021-04-27 17:13:35 +00:00
|
|
|
- "{{ data_folder }}/nginx/{{ base_domain }}.key"
|
|
|
|
- "{{ data_folder }}/nginx/{{ base_domain }}.crt"
|
2021-04-26 20:35:59 +00:00
|
|
|
- name: copy .conf file
|
|
|
|
template:
|
|
|
|
src: nginx.conf.j2
|
|
|
|
dest: "{{ data_folder }}/nginx/nginx.conf"
|
|
|
|
mode: '0755'
|
|
|
|
- name: run container
|
2021-04-22 23:04:44 +00:00
|
|
|
docker_container:
|
|
|
|
name: 'nginx'
|
|
|
|
image: nginx
|
|
|
|
volumes:
|
2021-04-26 20:35:59 +00:00
|
|
|
- "{{ data_folder }}/nginx/nginx.conf:/etc/nginx/nginx.conf"
|
2021-04-27 17:13:35 +00:00
|
|
|
- "{{ data_folder }}/nginx/{{ base_domain }}.key:/etc/nginx/{{ base_domain }}.key"
|
|
|
|
- "{{ data_folder }}/nginx/{{ base_domain }}.crt:/etc/nginx/{{ base_domain }}.crt"
|
2021-04-22 23:04:44 +00:00
|
|
|
- "{{ nginx_confd_folder }}:/etc/nginx/conf.d"
|
|
|
|
ports:
|
|
|
|
- "80:80"
|
2021-04-26 21:54:10 +00:00
|
|
|
- "443:443"
|
2021-04-22 23:04:44 +00:00
|
|
|
env:
|
|
|
|
NGINX_HOST: "{{ base_domain }}"
|
|
|
|
NGINX_PORT: '80'
|
|
|
|
state: started
|
2021-04-26 20:36:53 +00:00
|
|
|
restart: yes
|