Created
November 14, 2019 20:36
-
-
Save AndreasArne/6b627f15aabeecd435abd1e8e11f96c8 to your computer and use it in GitHub Desktop.
Tasks for installing nginx and setting up HTTPS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- name: Install packages | |
apt: | |
name: | |
- nginx | |
- python-certbot-nginx | |
state: present | |
- name: Check if certificate already exists. | |
stat: | |
path: /etc/letsencrypt/live/{{ domain_name }}/cert.pem | |
register: letsencrypt_cert | |
- debug: msg="{{ letsencrypt_cert.stat.exists }}" | |
- name: Stop services to allow certbot to generate a cert. | |
command: service nginx stop | |
when: not letsencrypt_cert.stat.exists | |
- name: Generate new certificate if one doesn't exist. | |
shell: "certbot certonly --standalone --noninteractive --expand --agree-tos --email {{ admin_email }} -d {{ domain_name }} -d www.{{ domain_name }}" | |
when: not letsencrypt_cert.stat.exists | |
- name: Remove default conf | |
file: | |
state: absent | |
path: /etc/nginx/sites-enabled/default |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment