Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

JulienPalard/ansible-nginx-letsencrypt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nginx with Letsencrypt

This role sets up nginx with letsencrypt.

It tries to be minimal by just creating snippets in /etc/nginx/snippets/letsencrypt-{your.domain}.conf so you can configure nginx yourself as you which.

Role Variables

The only mandatory variables are:

  • letsencrypt_certificates: A list of certificates, each being a list of domain names.
  • letsencrypt_email: Your email address.

Optional variables are:

Example Playbook

One certificate, one domain

Simpliest playbook with a single certificate and a single domain would look like:

- hosts: static_websites
  roles:
    - role: julienpalard.nginx_letsencrypt
      vars:
        letsencrypt_certificates: [[mdk.fr]]
        letsencrypt_email: julien@palard.fr

Note the double brackets, it's because we're asking for a single domain in a single certificate, see following examples for clarification.

One certificate, multiple domains

Just add your domains to the inner list, like:

- hosts: static_websites
  roles:
    - role: julienpalard.nginx_letsencrypt
      vars:
        letsencrypt_certificates: [[mdk.fr, www.mdk.fr]]
        letsencrypt_email: julien@palard.fr

Multiple certificates, multiple domains

The following playbook will generate three differnt certificates, the first one valid for mdk.fr, www.mdk.fr, and julien.palard.fr, the second one for wyz.fr and www.wyz.fr and the last one valid for tuw.fr and www.tuz.fr:

- hosts: static_websites
  roles:
    - role: julienpalard.nginx_letsencrypt
      vars:
        letsencrypt_certificates:
          - [mdk.fr, www.mdk.fr, julien.palard.fr]
          - [wyz.fr, www.wyz.fr]
          - [tuw.fr, www.tuw.fr]
        letsencrypt_email: julien@palard.fr

As a role dependency

This role fit nicely as another role dependency (in meta/main.yml), but do not use roles, use include_role, see ansible#34736:

dependencies:
  - role: julienpalard.nginx_letsencrypt
    vars:
      letsencrypt_certificates: [["{{ domain }}"]]

Or to concatenate a domain with a list of extra domains:

dependencies:
  - role: julienpalard.nginx_letsencrypt
    vars:
      letsencrypt_certificates: ["{{ [domain] | union(extra_certificates) }}"]

You can even extract the domain names from attributes of a map:

dependencies:
  - role: julienpalard.nginx_letsencrypt
    letsencrypt_certificates: {{ projects|map(attribute='domain')|list }}

License

MIT

Author Information

Julien Palard — https://mdk.fr

About

Minimalistic ansible role to setup letsencrypt with nginx.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages