Skip to content

Instantly share code, notes, and snippets.

@AndreasArne
Created November 14, 2019 20:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndreasArne/6b627f15aabeecd435abd1e8e11f96c8 to your computer and use it in GitHub Desktop.
Save AndreasArne/6b627f15aabeecd435abd1e8e11f96c8 to your computer and use it in GitHub Desktop.
Tasks for installing nginx and setting up HTTPS
- 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