Skip to content

Instantly share code, notes, and snippets.

@Informatic
Last active September 13, 2017 07:46
Show Gist options
  • Save Informatic/2ba8339d6faae9ac02f9f7d0f7b3c1e6 to your computer and use it in GitHub Desktop.
Save Informatic/2ba8339d6faae9ac02f9f7d0f7b3c1e6 to your computer and use it in GitHub Desktop.
ansible + letsencrypt + nginx

Small example on how to set up letsencrypt with nginx and ansible.

  1. Include nginx snippet in default configuration and configuration of every vhost you would like to have letsencrypt enabled for
  2. Make sure nginx is reloaded before letsencrypt role (protip: - meta: flush_handlers)
  3. Use playbook.yml as a further example.
location /.well-known/acme-challenge {
root /var/www/letsencrypt;
}
---
- hosts: all
vars:
letsencrypt_email: test@example
roles:
- nginx
- { role: letsencrypt, domains: ['example.com', 'alias.example.com'] }
---
- name: install letsencrypt
apt: name=letsencrypt state=latest
- name: create letsencrypt directory
file: name=/var/www/letsencrypt state=directory
- name: create certificate
shell: letsencrypt certonly -n --webroot -w /var/www/letsencrypt -m {{ letsencrypt_email }} --agree-tos -d {{ domains|join(",") }}
args:
creates: /etc/letsencrypt/live/{{ domains[0] }}
# TODO: Add renewal cronjob
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment