2022-05-22 04:19:56 +00:00
|
|
|
- name: Install nginx
|
|
|
|
apt:
|
|
|
|
name: nginx
|
|
|
|
state: present
|
|
|
|
update_cache: true
|
|
|
|
|
2022-05-23 07:32:56 +00:00
|
|
|
- name: Start nginx and enable on boot
|
|
|
|
service:
|
|
|
|
name: nginx
|
|
|
|
state: started
|
|
|
|
enabled: true
|
|
|
|
|
2022-05-22 04:19:56 +00:00
|
|
|
- name: Install nginx base configuration
|
|
|
|
template:
|
|
|
|
src: nginx.conf.j2
|
|
|
|
dest: /etc/nginx/nginx.conf
|
|
|
|
mode: '0644'
|
|
|
|
notify: reload_nginx
|
|
|
|
|
|
|
|
- name: Install nginx sites configuration
|
|
|
|
template:
|
|
|
|
src: server-nginx.conf.j2
|
2022-05-24 02:33:17 +00:00
|
|
|
dest: "/etc/nginx/sites-available/{{ item.domain }}.conf"
|
2022-05-22 04:19:56 +00:00
|
|
|
mode: '0644'
|
2022-05-23 07:32:56 +00:00
|
|
|
loop: "{{ proxy.servers }}"
|
2022-05-22 04:19:56 +00:00
|
|
|
notify: reload_nginx
|
2022-05-24 02:33:17 +00:00
|
|
|
register: nginx_sites
|
|
|
|
|
|
|
|
- name: Enable nginx sites configuration
|
|
|
|
file:
|
|
|
|
src: "/etc/nginx/sites-available/{{ item.item.domain }}.conf"
|
|
|
|
dest: "/etc/nginx/sites-enabled/{{ item.item.domain }}.conf"
|
|
|
|
state: link
|
|
|
|
loop: "{{ nginx_sites.results }}"
|
|
|
|
when: item.changed
|
|
|
|
notify: reload_nginx
|
2022-05-22 04:19:56 +00:00
|
|
|
|
|
|
|
- name: Generate self-signed certificate
|
|
|
|
shell: 'openssl req -newkey rsa:4096 -x509 -sha256 -days 3650 -nodes \
|
|
|
|
-subj "/C=US/ST=Local/L=Local/O=Org/OU=IT/CN=example.com" \
|
|
|
|
-keyout /etc/ssl/private/nginx-selfsigned.key \
|
|
|
|
-out /etc/ssl/certs/nginx-selfsigned.crt'
|
|
|
|
args:
|
|
|
|
creates: /etc/ssl/certs/nginx-selfsigned.crt
|
2022-05-24 02:33:17 +00:00
|
|
|
when: proxy.production is not defined or not proxy.production
|
2022-05-22 04:19:56 +00:00
|
|
|
notify: reload_nginx
|
|
|
|
|
2022-05-23 07:32:56 +00:00
|
|
|
- name: Install LE's certbot
|
|
|
|
apt:
|
|
|
|
name: ['certbot', 'python3-certbot-dns-cloudflare']
|
|
|
|
state: present
|
2022-05-24 02:33:17 +00:00
|
|
|
when: proxy.production is defined and proxy.production
|
2022-05-23 07:32:56 +00:00
|
|
|
|
|
|
|
- name: Install Cloudflare API token
|
|
|
|
template:
|
|
|
|
src: cloudflare.ini.j2
|
|
|
|
dest: /root/.cloudflare.ini
|
|
|
|
mode: '0600'
|
2022-05-24 02:33:17 +00:00
|
|
|
when: proxy.production is defined and proxy.production and proxy.dns_cloudflare is defined
|
2022-05-23 07:32:56 +00:00
|
|
|
|
|
|
|
- name: Create nginx post renewal hook directory
|
|
|
|
file:
|
|
|
|
path: /etc/letsencrypt/renewal-hooks/post
|
|
|
|
state: directory
|
2022-05-25 01:15:10 +00:00
|
|
|
when: proxy.production is defined and proxy.production
|
2022-05-23 07:32:56 +00:00
|
|
|
|
|
|
|
- name: Install nginx post renewal hook
|
|
|
|
copy:
|
2022-05-24 02:33:17 +00:00
|
|
|
src: reload-nginx.sh
|
|
|
|
dest: /etc/letsencrypt/renewal-hooks/post/reload-nginx.sh
|
2022-05-23 07:32:56 +00:00
|
|
|
mode: '0755'
|
2022-05-24 02:33:17 +00:00
|
|
|
when: proxy.production is defined and proxy.production
|
2022-05-23 07:32:56 +00:00
|
|
|
|
|
|
|
- name: Run Cloudflare DNS-01 challenges on wildcard domains
|
|
|
|
shell: '/usr/bin/certbot certonly \
|
|
|
|
--non-interactive \
|
|
|
|
--agree-tos \
|
|
|
|
--email "{{ proxy.dns_cloudflare.email }}" \
|
|
|
|
--dns-cloudflare \
|
|
|
|
--dns-cloudflare-credentials /root/.cloudflare.ini \
|
2022-05-24 02:33:17 +00:00
|
|
|
-d "*.{{ item }}" {{ proxy.dns_cloudflare.opts | default("") }}'
|
2022-05-23 07:32:56 +00:00
|
|
|
args:
|
|
|
|
creates: "/etc/letsencrypt/live/{{ item }}/fullchain.pem"
|
|
|
|
loop: "{{ proxy.dns_cloudflare.wildcard_domains }}"
|
2022-05-24 02:33:17 +00:00
|
|
|
when: proxy.production is defined and proxy.production and proxy.dns_cloudflare is defined
|
2022-05-23 07:32:56 +00:00
|
|
|
notify: reload_nginx
|