Compare commits

...
19 Commits
Author SHA1 Message Date
Jeff GeerlingandGitHub 222d57cb2e Merge pull request #14 from geerlingguy/certbot-auto-renew
Fixes #13: Certbot auto renew cron job
2017-01-21 15:37:44 -06:00
Jeff Geerling 7c8e2e5735 Install correct package on Debian. 2017-01-21 15:33:06 -06:00
Jeff Geerling b5ff8d4886 Update README regarding example usage. 2017-01-21 15:31:40 -06:00
Jeff Geerling bca9164582 Install cron in test environments so tests pass. 2017-01-21 15:28:26 -06:00
Jeff GeerlingandGitHub 353747a915 Merge pull request #7 from Brunty/patch-1
Updated README.md to reference geerlingguy.certbot
2017-01-21 15:17:46 -06:00
Jeff Geerling d76e3915fe Fixes #13: Add certbot-auto renew cron job. 2017-01-21 15:16:45 -06:00
Jeff Geerling a2f63847fd Fixes #9: Add more Galaxy tags. 2017-01-21 15:08:03 -06:00
Jeff Geerling 18e2752f0e Fix test failures on Ubuntu 12.04. 2016-11-23 09:27:48 -06:00
Jeff Geerling ea45b22546 Fix Ubuntu test failures due to apt update. 2016-11-23 09:04:28 -06:00
Jeff Geerling 565678e559 Remove sudo requirement from Travis build. 2016-09-25 15:49:13 -05:00
Jeff Geerling c84f967a08 Update travisfile to not require sudo. 2016-09-25 15:02:10 -05:00
Jeff Geerling 373fa29f60 Adjust Travis file for easier maintenance. 2016-08-31 20:25:44 -05:00
Jeff Geerling ca23b73996 Force update apt cache on Ubuntu. 2016-08-28 21:19:03 -05:00
Jeff Geerling 7daaa25cf2 Add required git dependency. 2016-08-28 21:14:54 -05:00
Jeff Geerling e9f5e5e30f Switch to using Docker registry containers for efficiency. 2016-08-28 21:11:13 -05:00
Matt BruntandGitHub eece6540a2 Updated README.md to reference geerlingguy.certbot
It now references geerlingguy.certbot - previously it was referencing geerlingguy.letsencrypt
2016-07-26 16:07:06 +01:00
Jeff Geerling c762892bb1 Fix broken CentOS tests; 'DistributionNotFound: jinja2'. 2016-07-10 22:27:51 -05:00
Jeff Geerling 65071dd992 Fixes #5: Ensure certbot-auto is executable. 2016-07-10 22:21:19 -05:00
Jeff Geerling 444064222b Fixes #4: Update to use Certbot. Rename from letsencrypt to certbot. 2016-07-10 22:17:26 -05:00
13 changed files with 121 additions and 117 deletions
+22 -26
View File
@@ -1,53 +1,49 @@
---
sudo: required
services: docker
env:
- distribution: centos
version: 6
init: /sbin/init
run_opts: ""
- distribution: centos
version: 7
- distro: centos7
init: /usr/lib/systemd/systemd
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
- distribution: ubuntu
version: 14.04
- distro: centos6
init: /sbin/init
run_opts: ""
- distribution: ubuntu
version: 12.04
- distro: ubuntu1604
init: /lib/systemd/systemd
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
- distro: ubuntu1404
init: /sbin/init
run_opts: ""
- distro: ubuntu1204
init: /sbin/init
run_opts: ""
services:
- docker
before_install:
# Pull container
- 'sudo docker pull ${distribution}:${version}'
# Customize container
- 'sudo docker build --rm=true --file=tests/Dockerfile.${distribution}-${version} --tag=${distribution}-${version}:ansible tests'
# Pull container.
- 'docker pull geerlingguy/docker-${distro}-ansible:latest'
script:
- container_id=$(mktemp)
# Run container in detached state
- 'sudo docker run --detach --volume="${PWD}":/etc/ansible/roles/role_under_test:ro ${run_opts} ${distribution}-${version}:ansible "${init}" > "${container_id}"'
# Run container in detached state.
- 'docker run --detach --volume="${PWD}":/etc/ansible/roles/role_under_test:ro ${run_opts} geerlingguy/docker-${distro}-ansible:latest "${init}" > "${container_id}"'
# Install dependencies.
- 'docker exec "$(cat ${container_id})" ansible-galaxy install -r /etc/ansible/roles/role_under_test/tests/requirements.yml'
# Ansible syntax check.
- 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml --syntax-check'
- 'docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml --syntax-check'
# Test role.
- 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml'
- 'docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml'
# Test role idempotence.
- idempotence=$(mktemp)
- docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml | tee -a ${idempotence}
- >
sudo docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml
tail ${idempotence}
| grep -q 'changed=0.*failed=0'
&& (echo 'Idempotence test: pass' && exit 0)
|| (echo 'Idempotence test: fail' && exit 1)
# Clean up
- 'sudo docker stop "$(cat ${container_id})"'
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
+44 -7
View File
@@ -1,16 +1,31 @@
# Ansible Role: Let's Encrypt
# Ansible Role: Certbot (for Let's Encrypt)
[![Build Status](https://travis-ci.org/geerlingguy/ansible-role-letsencrypt.svg?branch=master)](https://travis-ci.org/geerlingguy/ansible-role-letsencrypt)
[![Build Status](https://travis-ci.org/geerlingguy/ansible-role-certbot.svg?branch=master)](https://travis-ci.org/geerlingguy/ansible-role-certbot)
Installs Let's Encrypt for RHEL/CentOS or Debian/Ubuntu.
Installs Certbot (for Let's Encrypt) for RHEL/CentOS or Debian/Ubuntu.
## Requirements
Let's Encrypt requires `git` to be installed. You can install using the `geerlingguy.git` role.
Certbot requires Git to be installed. You can install Git using the `geerlingguy.git` role.
## Role Variables
None.
certbot_repo: https://github.com/certbot/certbot.git
certbot_version: master
certbot_keep_updated: yes
Certbot code repository options. This role clones the agent from the configured repo, then makes the `certbot-auto` script executable.
certbot_dir: /opt/certbot
The directory inside which Certbot will be cloned.
certbot_auto_renew: true
certbot_auto_renew_user: "{{ ansible_user }}"
certbot_auto_renew_hour: 3
certbot_auto_renew_minute: 30
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-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.
## Dependencies
@@ -19,8 +34,30 @@ None.
## Example Playbook
- hosts: servers
vars:
certbot_auto_renew_user: your_username_here
certbot_auto_renew_minute: 20
certbot_auto_renew_hour: 5
roles:
- geerlingguy.letsencrypt
- geerlingguy.certbot
After installation, you can create certificates using the `certbot-auto` script, which by default is installed inside the configured `certbot_dir`, so by default, `/opt/certbot/certbot-auto`. Here are some example commands to configure certificates with Certbot:
# Automatically add certs for all Apache virtualhosts (use with caution!).
/opt/certbot/certbot-auto --apache
# Generate certs, but don't modify Apache configuration (safer).
/opt/certbot/certbot-auto --apache certonly
By default, this role adds a cron job that will renew all installed certificates once per day at the hour and minute of your choosing.
You can test the auto-renewal (without actually renewing the cert) with the command:
/opt/certbot/certbot-auto renew --dry-run
See full documentation and options on the [Certbot website](https://certbot.eff.org/).
## License
@@ -28,4 +65,4 @@ MIT / BSD
## Author Information
This role was created in 2016 by [Jeff Geerling](http://jeffgeerling.com/), author of [Ansible for DevOps](http://ansiblefordevops.com/).
This role was created in 2016 by [Jeff Geerling](http://www.jeffgeerling.com/), author of [Ansible for DevOps](https://www.ansiblefordevops.com/).
+12 -4
View File
@@ -1,6 +1,14 @@
---
letsencrypt_repo: https://github.com/letsencrypt/letsencrypt
letsencrypt_version: master
letsencrypt_keep_updated: yes
# Where to get Certbot.
certbot_repo: https://github.com/certbot/certbot.git
certbot_version: master
certbot_keep_updated: yes
letsencrypt_dir: /opt/letsencrypt
# Where to put Certbot.
certbot_dir: /opt/certbot
# How to keep Certbot certs up to date.
certbot_auto_renew: true
certbot_auto_renew_user: "{{ ansible_user }}"
certbot_auto_renew_hour: 3
certbot_auto_renew_minute: 30
+7 -1
View File
@@ -3,7 +3,7 @@ dependencies: []
galaxy_info:
author: geerlingguy
description: "Let's Encrypt for RHEL/CentOS and Debian/Ubuntu."
description: "Certbot (for Let's Encrypt) for RHEL/CentOS and Debian/Ubuntu."
company: "Midwestern Mac, LLC"
license: "license (BSD, MIT)"
min_ansible_version: 1.8
@@ -22,3 +22,9 @@ galaxy_info:
- networking
- system
- web
- certbot
- letsencrypt
- encryption
- certificates
- ssl
- https
+19 -5
View File
@@ -1,7 +1,21 @@
---
- name: Clone Let's Encrypt into configured directory.
- name: Clone Certbot into configured directory.
git:
repo: "{{ letsencrypt_repo }}"
dest: "{{ letsencrypt_dir }}"
version: "{{ letsencrypt_version }}"
update: "{{ letsencrypt_keep_updated }}"
repo: "{{ certbot_repo }}"
dest: "{{ certbot_dir }}"
version: "{{ certbot_version }}"
update: "{{ certbot_keep_updated }}"
- name: Ensure certbot-auto is executable.
file:
path: "{{ certbot_dir }}/certbot-auto"
mode: 0755
- name: Add cron job for 'certbot-auto renew' (if configured).
cron:
name: Certbot automatic renewal.
job: "{{ certbot_dir }}/certbot-auto renew --quiet --no-self-upgrade"
minute: "{{ certbot_auto_renew_minute }}"
hour: "{{ certbot_auto_renew_hour }}"
user: "{{ certbot_auto_renew_user }}"
when: certbot_auto_renew
-19
View File
@@ -1,19 +0,0 @@
FROM centos:6
# Install Ansible
RUN yum -y update; yum clean all;
RUN yum -y install epel-release
RUN yum -y install git python-setuptools gcc sudo libffi-devel python-devel openssl-devel
RUN yum clean all
RUN easy_install pip
RUN pip install ansible
# Disable requiretty
RUN sed -i -e 's/^\(Defaults\s*requiretty\)/#--- \1/' /etc/sudoers
# Install Ansible inventory file
RUN mkdir - p /etc/ansible
RUN echo -e '[local]\nlocalhost ansible_connection=local' > /etc/ansible/hosts
CMD ["/usr/sbin/init"]
-29
View File
@@ -1,29 +0,0 @@
FROM centos:7
# Install systemd -- See https://hub.docker.com/_/centos/
RUN yum -y swap -- remove fakesystemd -- install systemd systemd-libs
RUN yum -y update; yum clean all; \
(cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -f /lib/systemd/system/multi-user.target.wants/*; \
rm -f /etc/systemd/system/*.wants/*; \
rm -f /lib/systemd/system/local-fs.target.wants/*; \
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -f /lib/systemd/system/basic.target.wants/*; \
rm -f /lib/systemd/system/anaconda.target.wants/*;
# Install Ansible
RUN yum -y install git python-setuptools gcc sudo libffi-devel python-devel openssl-devel
RUN yum clean all
RUN easy_install pip
RUN pip install ansible
# Disable requiretty
RUN sed -i -e 's/^\(Defaults\s*requiretty\)/#--- \1/' /etc/sudoers
# Install Ansible inventory file
RUN mkdir - p /etc/ansible
RUN echo -e '[local]\nlocalhost ansible_connection=local' > /etc/ansible/hosts
VOLUME ["/sys/fs/cgroup"]
CMD ["/usr/sbin/init"]
-11
View File
@@ -1,11 +0,0 @@
FROM ubuntu:12.04
RUN apt-get update
# Install Ansible
RUN apt-get install -y software-properties-common python-software-properties git
RUN apt-add-repository -y ppa:ansible/ansible
RUN apt-get update
RUN apt-get install -y ansible
# Install Ansible inventory file
RUN echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts
-11
View File
@@ -1,11 +0,0 @@
FROM ubuntu:14.04
RUN apt-get update
# Install Ansible
RUN apt-get install -y software-properties-common git
RUN apt-add-repository -y ppa:ansible/ansible
RUN apt-get update
RUN apt-get install -y ansible
# Install Ansible inventory file
RUN echo "[local]\nlocalhost ansible_connection=local" > /etc/ansible/hosts
+2
View File
@@ -0,0 +1,2 @@
---
- src: geerlingguy.git
+15
View File
@@ -1,5 +1,20 @@
---
- hosts: all
pre_tasks:
- name: Update apt cache.
apt: update_cache=yes cache_valid_time=600
when: ansible_os_family == 'Debian'
changed_when: false
- name: Install cron (RedHat).
yum: name=cronie state=present
when: ansible_os_family == 'RedHat'
- name: Install cron (Debian).
apt: name=cron state=present
when: ansible_os_family == 'Debian'
roles:
- geerlingguy.git
- role_under_test
-2
View File
@@ -1,2 +0,0 @@
---
samba_daemon: smbd
-2
View File
@@ -1,2 +0,0 @@
---
samba_daemon: smb