coopdevs.certbot_nginx
Certbot NGINX 
简单的 Ansible 角色,用于在 Ubuntu 16.04 和 Ubuntu 18.04 上安装带有 NGINX 插件的 certbot
。
此角色将:
- 添加
certbot
PPA 仓库 - 安装
certbot
和python-certbot-nginx
包 certbot
包会添加一个renew
的定时任务和系统定时器(更多信息)- 为指定的
domain_name
生成 Let's Encrypt SSL 证书。
警告
如果您已经安装了 Nginx 并且网站配置指向 /etc/letsencrypt
中的文件,则证书创建任务会失败(示例)。
一般建议在安装和配置 Nginx 之前执行此角色。
角色变量
domain_name: www.mydomain.io
letsencrypt_email: [email protected]
certbot_nginx_cert_name: mycert # 可选
certbot_version: 0.31.0-1+ubuntu{{ ansible_distribution_version }}.1+certbot+1 # 可选
certbot_nginx_version: 0.31.0-1+ubuntu{{ ansible_distribution_version }}.1+certbot+1 # 可选
如果设置了,certbot_nginx_cert_name
的值将传递给 certbot 的 --cert-name
参数,用于在 certbot 命令(如 certbot delete
)中识别证书。通过运行 certbot certificates
可以看到以此名称识别的证书列表。这个名称也将用于 /etc/letsencrypt/live/
中证书的文件路径。
示例剧本 - 单一证书
# 剧本
- hosts: servers
roles:
- role: coopdevs.certbot_nginx
vars:
domain_name: www.mydomain.io
letsencrypt_email: [email protected]
示例剧本 - 多个证书创建
也允许在同一主机上生成和管理多个证书。
您可以定义变量 domain_names
并在循环中配置角色以包含此角色。
# 剧本
- hosts: servers
roles:
- role: coopdevs.certbot_nginx
vars:
letsencrypt_email: [email protected]
- role: certificates
vars:
domain_names:
- community.coopdevs.org
- forms.coopdevs.org
创建一个包含 certbot_nginx
角色的自定义角色以生成证书:
# certificates.yml 角色
---
- name: 安装 SSL 证书
include_role:
name: vendor/coopdevs.certbot_nginx
tasks_from: certificate.yml
with_items: "{{ domain_names }}"
loop_control:
loop_var: domain_name
您需要声明
loop_control
将with_item
循环的item
变量映射到loop_var
值为domain_name
。请参阅loop_control
文档
更新现有证书
如果您的网站自证书创建以来发生了变化,您可以更新域名列表,角色将检查证书中域名与提供的领域列表之间的差异,并决定是否需要续订证书。如果您想强制续订过程,可以通过定义 certbot_force_update: true
或通过命令行传递 --extra-vars "certbot_force_update=true"
来做到。
Let's Encrypt 测试环境
此角色包含 letsencrypt_staging
变量,默认为 no
。出于开发或调试目的,可以将其设置为 yes
,例如通过 命令行传递变量 --extra-vars "letsencrypt_staging=yes"
这将使用 Let's Encrypt 测试环境 并减少置信限的可能性。
许可证
BSD
作者信息
Coopdevs http://coopdevs.org