mirror of
https://github.com/2martens/cloud-configuration.git
synced 2026-10-18 00:56:51 +02:00
55 lines
1.9 KiB
YAML
55 lines
1.9 KiB
YAML
---
|
|
- name: Determine if Nginx config already exists
|
|
ansible.builtin.stat:
|
|
path: /etc/nginx/sites-available/{{ spring_domain }}.conf
|
|
register: nginx_site
|
|
- name: Update Spring nginx site
|
|
when: nginx_site.stat.exists
|
|
ansible.builtin.template:
|
|
src: etc/nginx/sites-available/spring_domain_existing.conf.j2
|
|
dest: /etc/nginx/sites-available/{{ spring_domain }}.conf
|
|
owner: root
|
|
group: root
|
|
mode: "644"
|
|
force: true
|
|
lstrip_blocks: true
|
|
- name: Add Spring nginx site
|
|
when: not nginx_site.stat.exists
|
|
ansible.builtin.template:
|
|
src: etc/nginx/sites-available/spring_domain.conf.j2
|
|
dest: /etc/nginx/sites-available/{{ spring_domain }}.conf
|
|
owner: root
|
|
group: root
|
|
mode: "644"
|
|
force: false
|
|
lstrip_blocks: true
|
|
- name: Disable default site
|
|
ansible.builtin.command:
|
|
cmd: rm /etc/nginx/sites-enabled/default
|
|
removes: /etc/nginx/sites-enabled/default
|
|
- name: Enable Spring nginx site
|
|
when: not nginx_site.stat.exists
|
|
ansible.builtin.command:
|
|
cmd: ln -sf /etc/nginx/sites-available/{{ spring_domain }}.conf /etc/nginx/sites-enabled/{{ spring_domain }}.conf
|
|
creates: /etc/nginx/sites-enabled/{{ spring_domain }}.conf
|
|
notify: Reload nginx
|
|
- name: Check certificate existence
|
|
ansible.builtin.stat:
|
|
path: "/etc/letsencrypt/live/{{ spring_domain }}/cert.pem"
|
|
register: certificate
|
|
- name: Generate certificates
|
|
ansible.builtin.command:
|
|
cmd: >
|
|
certbot --nginx --non-interactive --keep-until-expiring
|
|
--no-eff-email
|
|
--email {{ admin_mail }}
|
|
--redirect
|
|
--renew-with-new-domains --agree-tos -d {{ spring_domain }}
|
|
creates: "/etc/letsencrypt/live/{{ spring_domain }}/cert.pem"
|
|
register: certbot_certificate_created
|
|
notify: Reload nginx
|
|
failed_when:
|
|
- "'Successfully received certificate.' not in certbot_certificate_created.stdout"
|
|
when:
|
|
- not certificate.stat.exists
|