From 170b337b177c3748e028c951195c1f8df0f97f58 Mon Sep 17 00:00:00 2001 From: muppeth Date: Fri, 2 Sep 2022 13:54:53 +0200 Subject: [PATCH] initial commit --- LICENSE | 22 ++++++++++++++++------ README.md | 5 ++--- defaults/main.yml | 19 +++++++++++++++++++ handlers/main.yml | 11 +++++++++++ tasks/cert.yml | 7 +++++++ tasks/client.yml | 38 ++++++++++++++++++++++++++++++++++++++ tasks/copy_ssl.yml | 20 ++++++++++++++++++++ tasks/main.yml | 9 +++++++++ 8 files changed, 122 insertions(+), 9 deletions(-) create mode 100644 defaults/main.yml create mode 100644 handlers/main.yml create mode 100644 tasks/cert.yml create mode 100644 tasks/client.yml create mode 100644 tasks/copy_ssl.yml create mode 100644 tasks/main.yml diff --git a/LICENSE b/LICENSE index 2071b23..84fc4ba 100644 --- a/LICENSE +++ b/LICENSE @@ -1,9 +1,19 @@ -MIT License +MIT License Copyright (c) 2022 "Stichting Disroot.org" -Copyright (c) +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. diff --git a/README.md b/README.md index 12acdd6..f75aeee 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..108a3a7 --- /dev/null +++ b/defaults/main.yml @@ -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 diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..140d79e --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,11 @@ +--- + +- name: reload nginx + command: nginx -t + notify: real-reload nginx + +- name: real-reload nginx + systemd: + name: nginx + state: reloaded + diff --git a/tasks/cert.yml b/tasks/cert.yml new file mode 100644 index 0000000..52979bb --- /dev/null +++ b/tasks/cert.yml @@ -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 diff --git a/tasks/client.yml b/tasks/client.yml new file mode 100644 index 0000000..32a1472 --- /dev/null +++ b/tasks/client.yml @@ -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 diff --git a/tasks/copy_ssl.yml b/tasks/copy_ssl.yml new file mode 100644 index 0000000..5bedff9 --- /dev/null +++ b/tasks/copy_ssl.yml @@ -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 diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..5b66385 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,9 @@ +--- + +- include: client.yml + when: install_letsencrypt == 'true' + +- include: cert.yml + when: install_letsencrypt == 'true' + +- include: copy_ssl.yml