75 lines
2.2 KiB
YAML
75 lines
2.2 KiB
YAML
---
|
|
- name: "Activar container nginx"
|
|
docker_container:
|
|
name: "nginx"
|
|
state: "started"
|
|
restart_policy: "unless-stopped"
|
|
image: "{{ nginx_image }}"
|
|
volumes:
|
|
- "{{ nginx_ssl_certificate }}:/etc/nginx/server.crt"
|
|
- "{{ nginx_ssl_private_key }}:/etc/nginx/server.key"
|
|
- "{{ nginx_config_volume }}:/etc/nginx/conf.d/"
|
|
- "{{ nginx_webroot_volume }}:/usr/share/nginx/html/"
|
|
networks:
|
|
- name: "{{ docker_network_name }}"
|
|
ports: "{{ nginx_publish_ports }}"
|
|
env:
|
|
register: "container"
|
|
|
|
- name: "Configurar volumen {{ nginx_config_volume }}"
|
|
docker_volume:
|
|
name: "{{ nginx_config_volume }}"
|
|
state: "present"
|
|
register: "st_c_volume"
|
|
|
|
- name: "Configurar volumen {{ nginx_webroot_volume }}"
|
|
docker_volume:
|
|
name: "{{ nginx_webroot_volume }}"
|
|
state: "present"
|
|
register: "st_w_volume"
|
|
|
|
# exportar punto de montaje del volumen
|
|
- set_fact:
|
|
nginx_config_mountpoint: "{{ st_c_volume.ansible_facts.docker_volume.Mountpoint }}"
|
|
nginx_webroot_mountpoint: "{{ st_w_volume.ansible_facts.docker_volume.Mountpoint }}"
|
|
|
|
# TODO: creo que estas tareas se deberian hacer desde dentro de un container
|
|
- copy:
|
|
content: |
|
|
ssl_certificate /etc/nginx/server.crt;
|
|
ssl_certificate_key /etc/nginx/server.key;
|
|
dest: "{{ nginx_config_mountpoint }}/00_ssl.conf"
|
|
notify: "restart nginx container"
|
|
|
|
- copy:
|
|
content: |
|
|
server {
|
|
listen 80 {{ nginx_http_listen_args | join (' ') }};
|
|
server_name _;
|
|
root /usr/share/nginx/html;
|
|
include /etc/nginx/conf.d/common/*.conf;
|
|
{% if nginx_redirect_https %}
|
|
location / {
|
|
rewrite ^ https://$http_host$request_uri permanent;
|
|
}
|
|
{% endif %}
|
|
include /etc/nginx/conf.d/locations-http/*.conf;
|
|
}
|
|
server {
|
|
listen 443 ssl {{ nginx_https_listen_args | join (' ') }};
|
|
server_name _;
|
|
root /usr/share/nginx/html;
|
|
include /etc/nginx/conf.d/common/*.conf;
|
|
include /etc/nginx/conf.d/locations/*.conf;
|
|
}
|
|
dest: "{{ nginx_config_mountpoint }}/10_server.conf"
|
|
notify: "restart nginx container"
|
|
|
|
- file:
|
|
name: "{{ nginx_config_mountpoint }}/{{ item }}"
|
|
state: "directory"
|
|
loop:
|
|
- common
|
|
- locations
|
|
- locations-http
|