ansible/roles/nginx/tasks/main.yml

43 lines
1.1 KiB
YAML
Raw Permalink Normal View History

2016-03-09 22:10:14 +01:00
---
- name: Install nginx
2017-09-09 11:22:43 +02:00
apt: name=nginx-light
2016-03-09 22:10:14 +01:00
- name: Create certificate directory
file: path=/etc/nginx/ssl state=directory mode=0750
2020-06-20 17:22:23 +02:00
when: nginx_ssl
2016-03-09 22:10:14 +01:00
- name: Ensure certificates are available
2021-09-30 16:00:35 +02:00
command:
cmd: >
openssl req -x509 -nodes -newkey rsa:2048
-keyout /etc/nginx/ssl/{{ ansible_fqdn }}.key
-out /etc/nginx/ssl/{{ ansible_fqdn }}.crt
-days 730 -subj "/CN={{ ansible_fqdn }}"
creates: /etc/nginx/ssl/{{ ansible_fqdn }}.crt
2020-06-20 17:22:23 +02:00
when: nginx_ssl
2016-03-09 22:10:14 +01:00
notify: Restart nginx
- name: Ensure correct certificate permissions
2016-04-01 08:10:00 +02:00
file: path=/etc/nginx/ssl/{{ ansible_fqdn }}.key owner=root mode=0400
2020-06-20 17:22:23 +02:00
when: nginx_ssl
2016-03-09 22:10:14 +01:00
notify: Restart nginx
- name: Create DH parameters
command: openssl dhparam -outform PEM -out {{ item }} 2048 creates={{ item }}
2020-06-20 17:22:23 +02:00
when: nginx_ssl
2016-03-09 22:10:14 +01:00
with_items:
- /etc/nginx/dhparam.pem
2016-06-18 13:21:21 +02:00
- name: Configure nginx
2021-09-30 16:00:35 +02:00
template: src=nginx.conf.j2 dest=/etc/nginx/nginx.conf
2016-03-09 22:25:48 +01:00
notify: Restart nginx
2016-06-18 13:21:21 +02:00
- name: Configure default vhost
2016-03-09 22:10:14 +01:00
template: src=default.j2 dest=/etc/nginx/sites-available/default
2020-06-20 17:22:23 +02:00
when: nginx_ssl
2016-03-09 22:10:14 +01:00
notify: Restart nginx
- name: Start nginx
service: name=nginx state=started enabled=yes