mirror of
https://github.com/geerlingguy/ansible-role-certbot.git
synced 2026-08-22 07:50:43 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cfd9655ed0 | ||
|
|
47203f3b92 | ||
|
|
a3b34ef499 | ||
|
|
199f940604 | ||
|
|
1b04270982 | ||
|
|
a056da763e | ||
|
|
2deba31679 | ||
|
|
d30ddd946a | ||
|
|
3d55be0a54 | ||
|
|
3f133ad7ab | ||
|
|
c6297ddebb | ||
|
|
eb4647ed9c | ||
|
|
31beafb338 | ||
|
|
1fc3a76d34 | ||
|
|
dd1f8bd22c | ||
|
|
de4cb90984 | ||
|
|
955ec8b17e | ||
|
|
a9a3ef77a3 | ||
|
|
e35a5d0fb9 | ||
|
|
854a36e048 | ||
|
|
2cad2addcd | ||
|
|
52a96f9bde | ||
|
|
7a7c1f8b06 | ||
|
|
40c4c1b433 | ||
|
|
bd58f8e72c | ||
|
|
123facdbab | ||
|
|
e1013946c5 | ||
|
|
b37af73500 | ||
|
|
23447ec217 | ||
|
|
50d8921ec2 | ||
|
|
2e13cb13cf | ||
|
|
e669ab0ac4 | ||
|
|
ca46eab49f | ||
|
|
5f476f829c | ||
|
|
34949a63d9 | ||
|
|
061509319f | ||
|
|
c7e5eec8cc | ||
|
|
23f593aaaf |
@@ -74,7 +74,7 @@ jobs:
|
||||
python-version: '3.x'
|
||||
|
||||
- name: Install test dependencies.
|
||||
run: pip3 install ansible molecule[docker] docker
|
||||
run: pip3 install ansible molecule molecule-plugins[docker] docker
|
||||
|
||||
- name: Run Molecule tests.
|
||||
run: molecule test
|
||||
|
||||
@@ -32,7 +32,9 @@ jobs:
|
||||
python-version: '3.x'
|
||||
|
||||
- name: Install Ansible.
|
||||
run: pip3 install ansible-base
|
||||
run: pip3 install ansible-core
|
||||
|
||||
- name: Trigger a new import on Galaxy.
|
||||
run: ansible-galaxy role import --api-key ${{ secrets.GALAXY_API_KEY }} $(echo ${{ github.repository }} | cut -d/ -f1) $(echo ${{ github.repository }} | cut -d/ -f2)
|
||||
run: >-
|
||||
ansible-galaxy role import --api-key ${{ secrets.GALAXY_API_KEY }}
|
||||
$(echo ${{ github.repository }} | cut -d/ -f1) $(echo ${{ github.repository }} | cut -d/ -f2)
|
||||
|
||||
@@ -5,6 +5,9 @@ rules:
|
||||
line-length:
|
||||
max: 180
|
||||
level: warning
|
||||
indentation:
|
||||
spaces: 2
|
||||
indent-sequences: consistent
|
||||
|
||||
ignore: |
|
||||
.github/stale.yml
|
||||
|
||||
@@ -20,20 +20,31 @@ Controls how Certbot is installed. Available options are 'package', 'snap', and
|
||||
certbot_auto_renew_user: "{{ ansible_user | default(lookup('env', 'USER')) }}"
|
||||
certbot_auto_renew_hour: "3"
|
||||
certbot_auto_renew_minute: "30"
|
||||
certbot_auto_renew_options: "--quiet --no-self-upgrade"
|
||||
certbot_auto_renew_options: "--quiet"
|
||||
|
||||
By default, this role configures a cron job to run under the provided user account at the given hour and minute, every day. The defaults run `certbot renew` (or `certbot-auto renew`) via cron every day at 03:30:00 by the user you use in your Ansible playbook. It's preferred that you set a custom user/hour/minute so the renewal is during a low-traffic period and done by a non-root user account.
|
||||
|
||||
### Automatic Certificate Generation
|
||||
|
||||
Currently there is one built-in method for generating new certificates using this role: `standalone`. Other methods (e.g. using nginx or apache and a webroot) may be added in the future.
|
||||
Currently the `standalone` and `webroot` method are supported for generating new certificates using this role.
|
||||
|
||||
**For a complete example**: see the fully functional test playbook in [molecule/default/playbook-standalone-nginx-aws.yml](molecule/default/playbook-standalone-nginx-aws.yml).
|
||||
|
||||
certbot_create_if_missing: false
|
||||
|
||||
Set `certbot_create_if_missing` to `yes` or `True` to let this role generate certs.
|
||||
|
||||
certbot_create_method: standalone
|
||||
|
||||
Set `certbot_create_if_missing` to `yes` or `True` to let this role generate certs. Set the method used for generating certs with the `certbot_create_method` variable—current allowed values include: `standalone`.
|
||||
Set the method used for generating certs with the `certbot_create_method` variable — current allowed values are: `standalone` or `webroot`.
|
||||
|
||||
certbot_testmode: false
|
||||
|
||||
Enable test mode to only run a test request without actually creating certificates.
|
||||
|
||||
certbot_hsts: false
|
||||
|
||||
Enable (HTTP Strict Transport Security) for the certificate generation.
|
||||
|
||||
certbot_admin_email: email@example.com
|
||||
|
||||
@@ -41,13 +52,14 @@ The email address used to agree to Let's Encrypt's TOS and subscribe to cert-rel
|
||||
|
||||
certbot_certs: []
|
||||
# - email: janedoe@example.com
|
||||
# webroot: "/var/www/html"
|
||||
# domains:
|
||||
# - example1.com
|
||||
# - example2.com
|
||||
# - domains:
|
||||
# - example3.com
|
||||
|
||||
A list of domains (and other data) for which certs should be generated. You can add an `email` key to any list item to override the `certbot_admin_email`.
|
||||
A list of domains (and other data) for which certs should be generated. You can add an `email` key to any list item to override the `certbot_admin_email`. When using the `webroot` creation method, a `webroot` item has to be provided, specifying which directory to use for the authentication. Make sure your webserver correctly delivers contents from this directory.
|
||||
|
||||
certbot_create_command: "{{ certbot_script }} certonly --standalone --noninteractive --agree-tos --email {{ cert_item.email | default(certbot_admin_email) }} -d {{ cert_item.domains | join(',') }}"
|
||||
|
||||
@@ -70,6 +82,10 @@ Setting `certbot_install_method: snap` configures this role to install Certbot v
|
||||
|
||||
This install method is currently experimental and may or may not work across all Linux distributions.
|
||||
|
||||
#### Webroot Certificate Generation
|
||||
|
||||
When using the `webroot` creation method, a `webroot` item has to be provided for every `certbot_certs` item, specifying which directory to use for the authentication. Also, make sure your webserver correctly delivers contents from this directory.
|
||||
|
||||
### Source Installation from Git
|
||||
|
||||
You can install Certbot from it's Git source repository if desired with `certbot_install_method: source`. This might be useful in several cases, but especially when older distributions don't have Certbot packages available (e.g. CentOS < 7, Ubuntu < 16.10 and Debian < 8).
|
||||
|
||||
+19
-4
@@ -4,28 +4,43 @@ certbot_auto_renew: true
|
||||
certbot_auto_renew_user: "{{ ansible_user | default(lookup('env', 'USER')) }}"
|
||||
certbot_auto_renew_hour: "3"
|
||||
certbot_auto_renew_minute: "30"
|
||||
certbot_auto_renew_options: "--quiet --no-self-upgrade"
|
||||
certbot_auto_renew_options: "--quiet"
|
||||
|
||||
certbot_testmode: false
|
||||
certbot_hsts: false
|
||||
|
||||
|
||||
# Parameters used when creating new Certbot certs.
|
||||
certbot_create_if_missing: false
|
||||
certbot_create_method: standalone
|
||||
certbot_admin_email: email@example.com
|
||||
|
||||
# Default webroot, overwritten by individual per-cert webroot directories
|
||||
certbot_webroot: /var/www/letsencrypt
|
||||
|
||||
certbot_certs: []
|
||||
# - email: janedoe@example.com
|
||||
# webroot: "/var/www/html/"
|
||||
# domains:
|
||||
# - example1.com
|
||||
# - example2.com
|
||||
# - domains:
|
||||
# - example3.com
|
||||
|
||||
certbot_create_command: >-
|
||||
{{ certbot_script }} certonly --standalone --noninteractive --agree-tos
|
||||
{{ certbot_script }} certonly --{{ certbot_create_method }}
|
||||
{{ '--hsts' if certbot_hsts else '' }}
|
||||
{{ '--test-cert' if certbot_testmode else '' }}
|
||||
--noninteractive --agree-tos
|
||||
--email {{ cert_item.email | default(certbot_admin_email) }}
|
||||
{{ '--webroot-path ' if certbot_create_method == 'webroot' else '' }}
|
||||
{{ cert_item.webroot | default(certbot_webroot) if certbot_create_method == 'webroot' else '' }}
|
||||
-d {{ cert_item.domains | join(',') }}
|
||||
{{ '--pre-hook /etc/letsencrypt/renewal-hooks/pre/stop_services'
|
||||
if certbot_create_standalone_stop_services
|
||||
if certbot_create_standalone_stop_services and certbot_create_method == 'standalone'
|
||||
else '' }}
|
||||
{{ '--post-hook /etc/letsencrypt/renewal-hooks/post/start_services'
|
||||
if certbot_create_standalone_stop_services
|
||||
if certbot_create_standalone_stop_services and certbot_create_method == 'standalone'
|
||||
else '' }}
|
||||
|
||||
certbot_create_standalone_stop_services:
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
---
|
||||
role_name_check: 1
|
||||
dependency:
|
||||
name: galaxy
|
||||
driver:
|
||||
@@ -8,7 +9,8 @@ platforms:
|
||||
image: "geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible:latest"
|
||||
command: ${MOLECULE_DOCKER_COMMAND:-""}
|
||||
volumes:
|
||||
- /sys/fs/cgroup:/sys/fs/cgroup:ro
|
||||
- /sys/fs/cgroup:/sys/fs/cgroup:rw
|
||||
cgroupns_mode: host
|
||||
privileged: true
|
||||
pre_build_image: true
|
||||
provisioner:
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
---
|
||||
- name: Check if certificate already exists.
|
||||
stat:
|
||||
path: /etc/letsencrypt/live/{{ cert_item.domains | first }}/cert.pem
|
||||
register: letsencrypt_cert
|
||||
|
||||
- name: Create webroot directory if it doesn't exist yet
|
||||
file:
|
||||
path: "{{ cert_item.webroot | default(certbot_webroot) }}"
|
||||
state: directory
|
||||
|
||||
- name: Generate new certificate if one doesn't exist.
|
||||
command: "{{ certbot_create_command }}"
|
||||
when: not letsencrypt_cert.stat.exists
|
||||
@@ -34,6 +34,7 @@
|
||||
src: /snap/bin/certbot
|
||||
dest: /usr/bin/certbot
|
||||
state: link
|
||||
ignore_errors: "{{ ansible_check_mode }}"
|
||||
|
||||
- name: Set Certbot script variable.
|
||||
set_fact:
|
||||
|
||||
@@ -21,5 +21,13 @@
|
||||
loop_control:
|
||||
loop_var: cert_item
|
||||
|
||||
- include_tasks: create-cert-webroot.yml
|
||||
with_items: "{{ certbot_certs }}"
|
||||
when:
|
||||
- certbot_create_if_missing
|
||||
- certbot_create_method == 'webroot'
|
||||
loop_control:
|
||||
loop_var: cert_item
|
||||
|
||||
- import_tasks: renew-cron.yml
|
||||
when: certbot_auto_renew
|
||||
|
||||
+13
-17
@@ -9,26 +9,22 @@
|
||||
|
||||
- block:
|
||||
|
||||
- name: Enable DNF module for CentOS 8.3+.
|
||||
shell: |
|
||||
dnf config-manager --set-enabled powertools
|
||||
args:
|
||||
warn: false
|
||||
register: dnf_module_enable
|
||||
changed_when: false
|
||||
- name: Enable DNF module for CentOS 8.3+.
|
||||
shell: |
|
||||
dnf config-manager --set-enabled powertools
|
||||
register: dnf_module_enable
|
||||
changed_when: false
|
||||
|
||||
when: ansible_facts['distribution_version'] is version('8.3', '>=')
|
||||
when: ansible_facts['distribution_version'] is version('8.3', '>=')
|
||||
|
||||
- name: Enable DNF module for CentOS 8.0–8.2.
|
||||
shell: |
|
||||
dnf config-manager --set-enabled PowerTools
|
||||
args:
|
||||
warn: false
|
||||
register: dnf_module_enable
|
||||
changed_when: false
|
||||
- name: Enable DNF module for CentOS 8.0–8.2.
|
||||
shell: |
|
||||
dnf config-manager --set-enabled PowerTools
|
||||
register: dnf_module_enable
|
||||
changed_when: false
|
||||
|
||||
when: ansible_facts['distribution_version'] is version('8.2', '<=')
|
||||
|
||||
when:
|
||||
- ansible_distribution == 'CentOS'
|
||||
- ansible_distribution_major_version | int >= 8
|
||||
- ansible_distribution == 'CentOS'
|
||||
- ansible_distribution_major_version | int >= 8
|
||||
|
||||
Reference in New Issue
Block a user