mirror of
https://github.com/geerlingguy/ansible-role-certbot.git
synced 2026-08-22 07:50:43 +02:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
df67d6826d | ||
|
|
c8ca60dbf4 |
@@ -12,7 +12,6 @@ onlyLabels: []
|
|||||||
|
|
||||||
# Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable
|
# Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable
|
||||||
exemptLabels:
|
exemptLabels:
|
||||||
- bug
|
|
||||||
- pinned
|
- pinned
|
||||||
- security
|
- security
|
||||||
- planned
|
- planned
|
||||||
|
|||||||
@@ -53,10 +53,9 @@ jobs:
|
|||||||
- distro: debian10
|
- distro: debian10
|
||||||
playbook: converge.yml
|
playbook: converge.yml
|
||||||
experimental: false
|
experimental: false
|
||||||
# Source install started failing recently.
|
- distro: centos7
|
||||||
# - distro: centos7
|
playbook: playbook-source-install.yml
|
||||||
# playbook: playbook-source-install.yml
|
experimental: false
|
||||||
# experimental: false
|
|
||||||
|
|
||||||
- distro: centos7
|
- distro: centos7
|
||||||
playbook: playbook-snap-install.yml
|
playbook: playbook-snap-install.yml
|
||||||
|
|||||||
@@ -32,9 +32,7 @@ jobs:
|
|||||||
python-version: '3.x'
|
python-version: '3.x'
|
||||||
|
|
||||||
- name: Install Ansible.
|
- name: Install Ansible.
|
||||||
run: pip3 install ansible-core
|
run: pip3 install ansible-base
|
||||||
|
|
||||||
- name: Trigger a new import on Galaxy.
|
- name: Trigger a new import on Galaxy.
|
||||||
run: >-
|
run: ansible-galaxy role import --api-key ${{ secrets.GALAXY_API_KEY }} $(echo ${{ github.repository }} | cut -d/ -f1) $(echo ${{ github.repository }} | cut -d/ -f2)
|
||||||
ansible-galaxy role import --api-key ${{ secrets.GALAXY_API_KEY }}
|
|
||||||
$(echo ${{ github.repository }} | cut -d/ -f1) $(echo ${{ github.repository }} | cut -d/ -f2)
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ extends: default
|
|||||||
|
|
||||||
rules:
|
rules:
|
||||||
line-length:
|
line-length:
|
||||||
max: 180
|
max: 120
|
||||||
level: warning
|
level: warning
|
||||||
|
|
||||||
ignore: |
|
ignore: |
|
||||||
|
|||||||
@@ -26,25 +26,14 @@ By default, this role configures a cron job to run under the provided user accou
|
|||||||
|
|
||||||
### Automatic Certificate Generation
|
### Automatic Certificate Generation
|
||||||
|
|
||||||
Currently the `standalone` and `webroot` method are supported for generating new certificates using this role.
|
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.
|
||||||
|
|
||||||
**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).
|
**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
|
certbot_create_if_missing: false
|
||||||
|
|
||||||
Set `certbot_create_if_missing` to `yes` or `True` to let this role generate certs.
|
|
||||||
|
|
||||||
certbot_create_method: standalone
|
certbot_create_method: standalone
|
||||||
|
|
||||||
Set the method used for generating certs with the `certbot_create_method` variable — current allowed values are: `standalone` or `webroot`.
|
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`.
|
||||||
|
|
||||||
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
|
certbot_admin_email: email@example.com
|
||||||
|
|
||||||
@@ -52,14 +41,13 @@ The email address used to agree to Let's Encrypt's TOS and subscribe to cert-rel
|
|||||||
|
|
||||||
certbot_certs: []
|
certbot_certs: []
|
||||||
# - email: janedoe@example.com
|
# - email: janedoe@example.com
|
||||||
# webroot: "/var/www/html"
|
|
||||||
# domains:
|
# domains:
|
||||||
# - example1.com
|
# - example1.com
|
||||||
# - example2.com
|
# - example2.com
|
||||||
# - domains:
|
# - domains:
|
||||||
# - example3.com
|
# - 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`. 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.
|
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`.
|
||||||
|
|
||||||
certbot_create_command: "{{ certbot_script }} certonly --standalone --noninteractive --agree-tos --email {{ cert_item.email | default(certbot_admin_email) }} -d {{ cert_item.domains | join(',') }}"
|
certbot_create_command: "{{ certbot_script }} certonly --standalone --noninteractive --agree-tos --email {{ cert_item.email | default(certbot_admin_email) }} -d {{ cert_item.domains | join(',') }}"
|
||||||
|
|
||||||
@@ -82,10 +70,6 @@ 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.
|
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
|
### 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).
|
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).
|
||||||
|
|||||||
+1
-22
@@ -6,42 +6,21 @@ certbot_auto_renew_hour: "3"
|
|||||||
certbot_auto_renew_minute: "30"
|
certbot_auto_renew_minute: "30"
|
||||||
certbot_auto_renew_options: "--quiet --no-self-upgrade"
|
certbot_auto_renew_options: "--quiet --no-self-upgrade"
|
||||||
|
|
||||||
certbot_testmode: false
|
|
||||||
certbot_hsts: false
|
|
||||||
|
|
||||||
|
|
||||||
# Parameters used when creating new Certbot certs.
|
# Parameters used when creating new Certbot certs.
|
||||||
certbot_create_if_missing: false
|
certbot_create_if_missing: false
|
||||||
certbot_create_method: standalone
|
certbot_create_method: standalone
|
||||||
certbot_admin_email: email@example.com
|
certbot_admin_email: email@example.com
|
||||||
|
|
||||||
# Default webroot, overwritten by individual per-cert webroot directories
|
|
||||||
certbot_webroot: /var/www/letsencrypt
|
|
||||||
|
|
||||||
certbot_certs: []
|
certbot_certs: []
|
||||||
# - email: janedoe@example.com
|
# - email: janedoe@example.com
|
||||||
# webroot: "/var/www/html/"
|
|
||||||
# domains:
|
# domains:
|
||||||
# - example1.com
|
# - example1.com
|
||||||
# - example2.com
|
# - example2.com
|
||||||
# - domains:
|
# - domains:
|
||||||
# - example3.com
|
# - example3.com
|
||||||
|
|
||||||
certbot_create_command: >-
|
certbot_create_command: >-
|
||||||
{{ certbot_script }} certonly --{{ certbot_create_method }}
|
{{ certbot_script }} certonly --standalone --noninteractive --agree-tos
|
||||||
{{ '--hsts' if certbot_hsts else '' }}
|
|
||||||
{{ '--test-cert' if certbot_testmode else '' }}
|
|
||||||
--noninteractive --agree-tos
|
|
||||||
--email {{ cert_item.email | default(certbot_admin_email) }}
|
--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(',') }}
|
-d {{ cert_item.domains | join(',') }}
|
||||||
{{ '--pre-hook /etc/letsencrypt/renewal-hooks/pre/stop_services'
|
|
||||||
if certbot_create_standalone_stop_services
|
|
||||||
else '' }}
|
|
||||||
{{ '--post-hook /etc/letsencrypt/renewal-hooks/post/start_services'
|
|
||||||
if certbot_create_standalone_stop_services
|
|
||||||
else '' }}
|
|
||||||
|
|
||||||
certbot_create_standalone_stop_services:
|
certbot_create_standalone_stop_services:
|
||||||
- nginx
|
- nginx
|
||||||
|
|||||||
@@ -4,39 +4,20 @@
|
|||||||
path: /etc/letsencrypt/live/{{ cert_item.domains | first | replace('*.', '') }}/cert.pem
|
path: /etc/letsencrypt/live/{{ cert_item.domains | first | replace('*.', '') }}/cert.pem
|
||||||
register: letsencrypt_cert
|
register: letsencrypt_cert
|
||||||
|
|
||||||
- name: Ensure pre and post hook folders exist.
|
- name: Stop services to allow certbot to generate a cert.
|
||||||
file:
|
service:
|
||||||
path: /etc/letsencrypt/renewal-hooks/{{ item }}
|
name: "{{ item }}"
|
||||||
state: directory
|
state: stopped
|
||||||
mode: 0755
|
when: not letsencrypt_cert.stat.exists
|
||||||
owner: root
|
with_items: "{{ certbot_create_standalone_stop_services }}"
|
||||||
group: root
|
|
||||||
with_items:
|
|
||||||
- pre
|
|
||||||
- post
|
|
||||||
|
|
||||||
- name: Create pre hook to stop services.
|
|
||||||
template:
|
|
||||||
src: stop_services.j2
|
|
||||||
dest: /etc/letsencrypt/renewal-hooks/pre/stop_services
|
|
||||||
owner: root
|
|
||||||
group: root
|
|
||||||
mode: 0750
|
|
||||||
when:
|
|
||||||
- certbot_create_standalone_stop_services is defined
|
|
||||||
- certbot_create_standalone_stop_services
|
|
||||||
|
|
||||||
- name: Create post hook to start services.
|
|
||||||
template:
|
|
||||||
src: start_services.j2
|
|
||||||
dest: /etc/letsencrypt/renewal-hooks/post/start_services
|
|
||||||
owner: root
|
|
||||||
group: root
|
|
||||||
mode: 0750
|
|
||||||
when:
|
|
||||||
- certbot_create_standalone_stop_services is defined
|
|
||||||
- certbot_create_standalone_stop_services
|
|
||||||
|
|
||||||
- name: Generate new certificate if one doesn't exist.
|
- name: Generate new certificate if one doesn't exist.
|
||||||
command: "{{ certbot_create_command }}"
|
command: "{{ certbot_create_command }}"
|
||||||
when: not letsencrypt_cert.stat.exists
|
when: not letsencrypt_cert.stat.exists
|
||||||
|
|
||||||
|
- name: Start services after cert has been generated.
|
||||||
|
service:
|
||||||
|
name: "{{ item }}"
|
||||||
|
state: started
|
||||||
|
when: not letsencrypt_cert.stat.exists
|
||||||
|
with_items: "{{ certbot_create_standalone_stop_services }}"
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
---
|
|
||||||
- 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
|
|
||||||
@@ -16,7 +16,6 @@
|
|||||||
src: /var/lib/snapd/snap
|
src: /var/lib/snapd/snap
|
||||||
dest: /snap
|
dest: /snap
|
||||||
state: link
|
state: link
|
||||||
when: ansible_os_family != "Debian"
|
|
||||||
|
|
||||||
- name: Update snap after install.
|
- name: Update snap after install.
|
||||||
shell: snap install core; snap refresh core
|
shell: snap install core; snap refresh core
|
||||||
@@ -34,7 +33,6 @@
|
|||||||
src: /snap/bin/certbot
|
src: /snap/bin/certbot
|
||||||
dest: /usr/bin/certbot
|
dest: /usr/bin/certbot
|
||||||
state: link
|
state: link
|
||||||
ignore_errors: "{{ ansible_check_mode }}"
|
|
||||||
|
|
||||||
- name: Set Certbot script variable.
|
- name: Set Certbot script variable.
|
||||||
set_fact:
|
set_fact:
|
||||||
|
|||||||
@@ -21,13 +21,5 @@
|
|||||||
loop_control:
|
loop_control:
|
||||||
loop_var: cert_item
|
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
|
- import_tasks: renew-cron.yml
|
||||||
when: certbot_auto_renew
|
when: certbot_auto_renew
|
||||||
|
|||||||
+1
-15
@@ -7,9 +7,7 @@
|
|||||||
name: dnf-plugins-core
|
name: dnf-plugins-core
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
- block:
|
- name: Enable DNF module for CentOS 8+.
|
||||||
|
|
||||||
- name: Enable DNF module for CentOS 8.3+.
|
|
||||||
shell: |
|
shell: |
|
||||||
dnf config-manager --set-enabled powertools
|
dnf config-manager --set-enabled powertools
|
||||||
args:
|
args:
|
||||||
@@ -17,18 +15,6 @@
|
|||||||
register: dnf_module_enable
|
register: dnf_module_enable
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
when: ansible_facts['distribution_version'] is version('8.2', '<=')
|
|
||||||
|
|
||||||
when:
|
when:
|
||||||
- ansible_distribution == 'CentOS'
|
- ansible_distribution == 'CentOS'
|
||||||
- ansible_distribution_major_version | int >= 8
|
- ansible_distribution_major_version | int >= 8
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
# {{ ansible_managed }}
|
|
||||||
|
|
||||||
{% for item in certbot_create_standalone_stop_services %}
|
|
||||||
echo "starting service {{ item }}"
|
|
||||||
{% if ansible_service_mgr == 'systemd' %}
|
|
||||||
systemctl start {{ item }}
|
|
||||||
{% elif ansible_service_mgr == 'upstart' %}
|
|
||||||
initctl start {{ item }}
|
|
||||||
{% elif ansible_service_mgr == 'openrc' %}
|
|
||||||
rc-service {{ item }} start
|
|
||||||
{% else %}
|
|
||||||
service {{ item }} start
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
# {{ ansible_managed }}
|
|
||||||
|
|
||||||
{% for item in certbot_create_standalone_stop_services %}
|
|
||||||
echo "stopping service {{ item }}"
|
|
||||||
{% if ansible_service_mgr == 'systemd' %}
|
|
||||||
systemctl stop {{ item }}
|
|
||||||
{% elif ansible_service_mgr == 'upstart' %}
|
|
||||||
initctl stop {{ item }}
|
|
||||||
{% elif ansible_service_mgr == 'openrc' %}
|
|
||||||
rc-service {{ item }} stop
|
|
||||||
{% else %}
|
|
||||||
service {{ item }} stop
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
|
||||||
Reference in New Issue
Block a user