initial commit

This commit is contained in:
muppeth 2022-09-02 13:54:53 +02:00
parent 8e7b11b7e1
commit 170b337b17
Signed by: muppeth
GPG Key ID: 0EBC7B9848D04031
8 changed files with 122 additions and 9 deletions

22
LICENSE
View File

@ -1,9 +1,19 @@
MIT License
MIT License Copyright (c) 2022 "Stichting Disroot.org"
Copyright (c) <year> <copyright holders>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -1,3 +1,2 @@
# letsencrypt
Role that installs certbot and using nginx obtains and renewes certificates.
# Letsencrypt Ansible role
Role that installs certbot and using nginx obtains and renewes certificates.

19
defaults/main.yml Normal file
View File

@ -0,0 +1,19 @@
---
letsencrypt_certbot_appdir: /opt/certbot
letsencrypt_email: yourmail@example.com
letsencrypt_domain: example.com
letsencrypt_rsa_kaysize: '4096'
install_letsencrypt: 'false'
letsencrypt_domains:
- name: service.example.org
letsencrypt_copy_certs: 'false'
letsencrypt_copy_cert_from:
- name: ''
letsencrypt_domains: ''
letsencrypt_services:
- nginx

11
handlers/main.yml Normal file
View File

@ -0,0 +1,11 @@
---
- name: reload nginx
command: nginx -t
notify: real-reload nginx
- name: real-reload nginx
systemd:
name: nginx
state: reloaded

7
tasks/cert.yml Normal file
View File

@ -0,0 +1,7 @@
---
- name: '[CERT] - Generate or renew certificates'
command: /usr/bin/certbot certonly --rsa-key-size {{ letsencrypt_rsa_kaysize }} --agree-tos --keep-until-expiring --non-interactive --webroot --webroot-path {{ letsencrypt_webroot_path }} -m {{ letsencrypt_email }} --domains {{ item.name }}
with_items: "{{ letsencrypt_domains }}"
notify:
- reload nginx

38
tasks/client.yml Normal file
View File

@ -0,0 +1,38 @@
---
- name: '[CERTBOT] - Install dependencies'
apt:
name: "{{ item }}"
state: present
with_items:
- python3
- python3-venv
- libaugeas0
- ca-certificates
- name: '[CERTBOT] - Create app dir'
file:
path: '{{ letsencrypt_certbot_appdir }}'
state: 'directory'
- name: '[CERTBOT] - Upgrade pip'
pip:
name: 'pip'
virtualenv: '{{ letsencrypt_certbot_appdir }}'
- name: '[CERTBOT] - Install certbot'
pip:
name: 'certbot'
virtualenv: '{{ letsencrypt_certbot_appdir }}'
- name: '[CERTBOT] - Create symbolic link to bin file'
file:
src: "{{ letsencrypt_certbot_appdir }}/bin/certbot"
dest: "/usr/bin/certbot"
state: link
- name: '[CERTBOT] - Create webroot directory'
file:
path: "{{ letsencrypt_webroot_path }}"
state: directory
mode: 0755
owner: www-data

20
tasks/copy_ssl.yml Normal file
View File

@ -0,0 +1,20 @@
---
- name: '[COPY SSL] - Fetch SSL Certificates'
synchronize:
mode: pull
src: '/etc/letsencrypt/'
dest: '/etc/ansible/ssl/{{ inventory_hostname }}'
when: install_letsencrypt == 'true'
notify:
- reload nginx
- name: '[COPY SSL] - Copy SSL certificates to containers behind proxy'
synchronize:
src: '/etc/ansible/ssl/{{ item.name }}/'
dest: '/etc/letsencrypt/'
when: letsencrypt_copy_certs == 'true'
with_items: '{{ letsencrypt_copy_cert_from }}'
notify:
- reload nginx

9
tasks/main.yml Normal file
View File

@ -0,0 +1,9 @@
---
- include: client.yml
when: install_letsencrypt == 'true'
- include: cert.yml
when: install_letsencrypt == 'true'
- include: copy_ssl.yml