thiagoalmeidasa.certbot_route53

Ansible角色:Certbot(用于Let's Encrypt)

构建状态

安装和配置Certbot(用于Let's Encrypt)。

需求

如果从源代码安装,必须需要Git。您可以使用geerlingguy.git角色来安装Git。

通常,从源代码安装(请参阅从Git源安装部分)能更好地使用Certbot和Let's Encrypt,特别是如果您使用的是较旧的操作系统版本。

角色变量

变量certbot_install_from_source控制是否从Git或软件包管理安装Certbot。后者是默认设置,因此该变量默认值为no

certbot_auto_renew: true
certbot_auto_renew_user: root
certbot_auto_renew_hour: "3"
certbot_auto_renew_minute: "30"
certbot_auto_renew_options: "--quiet --no-self-upgrade"

默认情况下,此角色配置一个cron作业,每天在指定的用户账户下的特定小时和分钟运行。默认设置为每天03:30:00通过Ansible剧本中的用户运行certbot renew(或certbot-auto renew)。建议您设置自定义用户/小时/分钟,以便在低流量时间段进行续订,并由非根用户执行。

自动证书生成

目前,有一种内置方法可以使用此角色生成新证书:standalone。其他方法(例如,使用nginx或apache和webroot)可能会在未来添加。

完整示例:请参阅molecule/default/playbook-standalone-nginx-aws.yml中的完整功能测试剧本。

certbot_create_if_missing: false
certbot_create_method: certonly

certbot_create_if_missing设置为yesTrue以允许此角色生成证书。通过certbot_create_method变量设置用于生成证书的方法——当前允许的值包括:certonly

certbot_admin_email: email@example.com

用于同意Let's Encrypt的服务条款并订阅证书相关通知的电子邮件地址。此处应自定义并设置为您或您的组织定期监控的电子邮件地址。

certbot_certs: []
  # - email: [email protected]
  #   domains:
  #     - example1.com
  #     - example2.com
  # - domains:
  #     - example3.com

应生成证书的域名(和其他数据)列表。您可以在任何列表项中添加email键来覆盖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定义用于生成证书的命令。

从Git源安装

如果需要,您可以从Git源代码库安装Certbot。这在多种情况下可能很有用,尤其是当旧版本的发行版没有可用的Certbot软件包时(例如,CentOS < 7,Ubuntu < 16.10 和 Debian < 8)。

certbot_install_from_source: false
certbot_repo: https://github.com/certbot/certbot.git
certbot_version: master
certbot_keep_updated: true

Certbot Git存储库选项。要从源安装,请将certbot_install_from_source设置为yes。这会克隆配置的certbot_repo,并遵循certbot_version的设置。如果certbot_keep_updated设置为yes,则每次运行此角色时,仓库都会更新。

certbot_dir: /opt/certbot

Certbot将被克隆的目录。

通配符证书

Let's Encrypt支持生成通配符证书,但生成和使用它们的过程略微复杂。请参阅this pull request中的评论,以获取有关如何使用此角色维护通配符证书的示例。

Michael Porter还有一份关于使用Ansible创建Let's Encrypt通配符证书的操作指南,特别是与Cloudflare一起使用。

依赖

无。

示例剧本

- hosts: servers

  vars:
    certbot_auto_renew_user: your_username_here
    certbot_auto_renew_minute: "20"
    certbot_auto_renew_hour: "5"

  roles:
    - thiagoalmeidasa.certbot_route53

请查看tests/目录中的其他示例。

手动创建证书

注意:您可以让这个角色自动生成证书;请参阅上面的“自动证书生成”文档。

您可以使用certbot(或certbot-auto)脚本手动创建证书(在Ubuntu 16.04上使用letsencrypt,或在从源/Git安装时使用/opt/certbot/certbot-auto)。以下是一些使用Certbot配置证书的示例命令:

# 自动为所有Apache虚拟主机添加证书(使用时需小心!)。
certbot --apache

# 生成证书,但不修改Apache配置(更加安全)。
certbot --apache certonly

如果您想完全自动化添加新证书的过程,但又不想使用此角色的内置功能,您可以使用命令行选项进行注册、接受服务条款,然后使用独立服务器生成证书:

  1. 确保任何监听在80和443端口的服务(Apache、Nginx、Varnish等)已停止。
  2. 使用类似certbot register --agree-tos --email [[email protected]]的命令注册 - 注意:在未来,当在同一服务器上生成其他证书时,您无需执行此步骤。
  3. 为DNS指向此服务器的域生成证书:certbot certonly --noninteractive --standalone -d example.com -d www.example.com
  4. 重新启动之前监听在80和443端口的服务。
  5. 更新您的Web服务器的虚拟主机TLS配置,以指向Certbot刚为您传入的域生成的新证书(fullchain.pem)和私钥(privkey.pem)。
  6. 重新加载或重启您的Web服务器,以便使用新的HTTPS虚拟主机配置。

Certbot证书自动续订

默认情况下,此角色添加一个cron作业,将在您选择的小时和分钟每天续订所有已安装的证书。

您可以使用以下命令测试自动续订(而不会实际续订证书):

/opt/certbot/certbot-auto renew --dry-run

有关完整文档和选项,请访问Certbot网站

许可证

MIT / BSD

安装
ansible-galaxy install thiagoalmeidasa.certbot_route53
许可证
mit
下载
4.9k
拥有者
Linux, open source, containers, docker. Nerd, with a big interest in the philosophical, biological, social, and cultural aspects of human life.