Compare commits

..
Author SHA1 Message Date
Jeff Geerling c27861fddc Issue #12: New include techniques require Ansible 2.4 or later. [ci skip] 2017-12-11 22:26:46 -06:00
Jeff Geerling d3f98e4258 Fixes #12: Document how to generate certs automatically using certbot --standalone. 2017-12-11 22:17:25 -06:00
Jeff Geerling 5f7c9e046c Issue #12: Fix standalone cert generation, add full build-test-teardown playbook. 2017-12-10 22:47:54 -06:00
Jeff Geerling 7651f0ac0b Issue #12: Add basic standalone certbot cert generation. 2017-12-06 22:48:30 -06:00
Jeff Geerling 574c0843c8 Fixes #37: Make renew command configurable. 2017-10-31 10:09:41 -05:00
Jeff Geerling f00a0ba181 Issue #6: Add more documentation around automatically generating certs. 2017-07-26 15:56:22 -05:00
Jeff Geerling 01d801c4b7 PR #19 follow-up: Docs fixes and reordering defaults. 2017-04-04 21:42:16 -05:00
Jeff GeerlingandGitHub 3b47bfb39e Merge pull request #19 from exploide/package-install
Install Certbot with package
2017-04-04 21:36:52 -05:00
Jeff Geerling da3ad13935 Update test script README. [ci skip] 2017-04-02 10:40:17 -05:00
exploide 932214698b Merge branch 'master' into package-install
this incorporates the changes that switched to a more efficient and compact test setup
2017-04-02 12:08:30 +02:00
Jeff Geerling 2f8a0f06d5 Switch to more efficient and compact test setup. 2017-04-01 22:45:12 -05:00
exploide 24d40c7b10 use test-source-install for Debian 8 since certbot (and letsencrypt) packages are only available from jessi-backports repo 2017-04-01 14:26:02 +02:00
exploide 1ca3e00b46 include distribution specific vars from files 2017-04-01 14:23:08 +02:00
Jeff Geerling 065d889858 Add a LICENSE file for MIT license. [ci skip] 2017-03-31 11:23:15 -05:00
Oskar SchöldströmandJannik V da5a6738d5 Show playbook right after distro in tests, change ubuntu1204 -> debian8 2017-03-25 18:15:43 +01:00
Oskar SchöldströmandJannik V e82a68e331 Support Ubuntu 16.04 out of the box 2017-03-25 18:15:43 +01:00
exploide 92ef96faff notes on distributions which do not ship certbot package 2017-03-19 17:17:43 +01:00
Oskar SchöldströmandJannik V c82468099b Run source-install tests for Ubuntu 14.04 as there's no package available 2017-03-19 17:08:04 +01:00
Oskar SchöldströmandJannik V 1f89316182 Fix Centos6 tests by testing source install 2017-03-19 17:08:04 +01:00
exploide 141dd08882 package module requires Ansible >= 2.0 2017-03-19 15:51:54 +01:00
exploide ef18833af5 made README more clear regarding package vs source installation 2017-03-19 14:49:28 +01:00
exploide afa993333f renamed certbot_from_git variable to certbot_install_from_source and fixed some wording 2017-03-19 14:38:07 +01:00
exploide 33724b0a93 this role is also compatible with Fedora
- mention Fedora in meta
- adapt description of role because this role should work on most distributions, not only EL and Debian/Ubuntu
2017-02-24 10:19:01 +01:00
exploide b82eeeed79 adapted README to cover install from package possibility 2017-02-24 10:16:07 +01:00
exploide f3a260e94e added possibility to install certbot from package management
- introduces a variable certbot_from_git
- adds install from package tasks
- makes a variable called certbot_script available (to handle certbot vs certbot-auto naming)
- fixes #18
2017-02-24 10:10:20 +01:00
exploide 35ceee9f1b restructured tasks such that subtask files are included
this is a preparation for installing certbot from package management
additionally, it might be useful when further tasks are added, e.g. for initial certificate retrieval
2017-02-23 20:00:42 +01:00
Jeff GeerlingandGitHub 3dedd45961 Merge pull request #16 from Kaurin/master
Git force: yes
2017-01-30 22:34:53 -06:00
Kaurin 806d612fab Adding 'force: yes' to the git section
to prevent 'local changes in working tree'
messages
2017-01-31 02:09:32 +00:00
Jeff Geerling 52dbc87e22 Update the author's URL. Now with more HTTPS! 2017-01-21 19:59:54 -06:00
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
24 changed files with 478 additions and 137 deletions
+2
View File
@@ -0,0 +1,2 @@
*.retry
tests/test.sh
+14 -46
View File
@@ -1,55 +1,23 @@
---
sudo: required
services: docker
env:
- distribution: centos
version: 6
init: /sbin/init
run_opts: ""
- distribution: centos
version: 7
init: /usr/lib/systemd/systemd
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
- distribution: ubuntu
version: 14.04
init: /sbin/init
run_opts: ""
- distribution: ubuntu
version: 12.04
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'
- distro: centos7
- distro: centos6
playbook: test-source-install.yml
- distro: ubuntu1604
- distro: ubuntu1404
playbook: test-source-install.yml
- distro: debian8
playbook: test-source-install.yml
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}"'
# Download test shim.
- wget -O ${PWD}/tests/test.sh https://gist.githubusercontent.com/geerlingguy/73ef1e5ee45d8694570f334be385e181/raw/
- chmod +x ${PWD}/tests/test.sh
# 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'
# Test role.
- 'sudo 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)
- sudo docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml | tee -a ${idempotence}
- >
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})"'
# Run tests.
- ${PWD}/tests/test.sh
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
+20
View File
@@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) 2017 Jeff Geerling
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+86 -11
View File
@@ -2,19 +2,72 @@
[![Build Status](https://travis-ci.org/geerlingguy/ansible-role-certbot.svg?branch=master)](https://travis-ci.org/geerlingguy/ansible-role-certbot)
Installs Certbot (for Let's Encrypt) for RHEL/CentOS or Debian/Ubuntu.
Installs and configures Certbot (for Let's Encrypt).
## Requirements
Certbot requires Git to be installed. You can install Git using the `geerlingguy.git` role.
If installing from source, Git is required. You can install Git using the `geerlingguy.git` role.
## Role Variables
The variable `certbot_install_from_source` controls whether to install Certbot from Git or package management. The latter is the default, so the variable defaults to `no`.
certbot_auto_renew: true
certbot_auto_renew_user: "{{ ansible_user }}"
certbot_auto_renew_hour: 3
certbot_auto_renew_minute: 30
certbot_auto_renew_options: "--quiet --no-self-upgrade"
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.
**For a complete example**: see the fully functional test playbook in [tests/test-standalone-nginx-aws.yml](tests/test-standalone-nginx-aws.yml).
certbot_create_if_missing: no
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`.
certbot_admin_email: email@example.com
The email address used to agree to Let's Encrypt's TOS and subscribe to cert-related notifications. This should be customized and set to an email address that you or your organization regularly monitors.
certbot_certs: []
# - email: janedoe@example.com
# 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`.
certbot_create_command: "{{ certbot_script }} certonly --standalone --noninteractive --agree-tos --email {{ cert_item.email | default(certbot_admin_email) }} -d {{ cert_item.domains | join(',') }}"
The `certbot_create_command` defines the command used to generate the cert.
#### Standalone Certificate Generation
certbot_create_standalone_stop_services:
- nginx
Services that should be stopped while `certbot` runs it's own standalone server on ports 80 and 443. If you're running Apache, set this to `apache2` (Ubuntu), or `httpd` (RHEL), or if you have Nginx on port 443 and something else on port 80 (e.g. Varnish, a Java app, or something else), add it to the list so it is stopped when the certificate is generated.
These services will only be stopped the first time a new cert is generated.
### Source Installation from Git
You can install Certbot from it's Git source repository if desired. 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).
certbot_install_from_source: no
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 Git repository options. To install from source, set `certbot_install_from_source` to `yes`. This clones the configured `certbot_repo`, respecting the `certbot_version` setting. If `certbot_keep_updated` is set to `yes`, the repository is updated every time this role runs.
certbot_dir: /opt/certbot
@@ -27,20 +80,42 @@ 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:
See other examples in the `tests/` directory.
### Manually creating certificates with certbot
_Note: You can have this role automatically generate certificates; see the "Automatic Certificate Generation" documentation above._
You can manually create certificates using the `certbot` (or `certbot-auto`) script (use `letsencrypt` on Ubuntu 16.04, or use `/opt/certbot/certbot-auto` if installing from source/Git. 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
certbot --apache
# Generate certs, but don't modify Apache configuration (safer).
/opt/certbot/certbot-auto --apache certonly
certbot --apache certonly
To set up renewals, you should run the following command periodically (e.g. once or twice per day):
If you want to fully automate the process of adding a new certificate, but don't want to use this role's built in functionality, you can do so using the command line options to register, accept the terms of service, and then generate a cert using the standalone server:
/opt/certbot/certbot-auto renew --quiet --no-self-upgrade
1. Make sure any services listening on ports 80 and 443 (Apache, Nginx, Varnish, etc.) are stopped.
2. Register with something like `certbot register --agree-tos --email [your-email@example.com]`
- Note: You won't need to do this step in the future, when generating additional certs on the same server.
3. Generate a cert for a domain whose DNS points to this server: `certbot certonly --noninteractive --standalone -d example.com -d www.example.com`
4. Re-start whatever was listening on ports 80 and 443 before.
5. Update your webserver's virtualhost TLS configuration to point at the new certificate (`fullchain.pem`) and private key (`privkey.pem`) Certbot just generated for the domain you passed in the `certbot` command.
6. Reload or restart your webserver so it uses the new HTTPS virtualhost configuration.
### Certbot certificate auto-renewal
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:
@@ -54,4 +129,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](https://www.jeffgeerling.com/), author of [Ansible for DevOps](https://www.ansiblefordevops.com/).
+28
View File
@@ -1,6 +1,34 @@
---
# Certbot auto-renew cron job configuration (for certificate renewals).
certbot_auto_renew: true
certbot_auto_renew_user: "{{ ansible_user }}"
certbot_auto_renew_hour: 3
certbot_auto_renew_minute: 30
certbot_auto_renew_options: "--quiet --no-self-upgrade"
# Parameters used when creating new Certbot certs.
certbot_create_if_missing: no
certbot_create_method: standalone
certbot_admin_email: email@example.com
certbot_certs: []
# - email: janedoe@example.com
# domains:
# - example1.com
# - example2.com
# - domains:
# - example3.com
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_standalone_stop_services:
- nginx
# - apache
# - varnish
# To install from source (on older OSes or if you need a specific or newer
# version of Certbot), set this variable to `yes` and configure other options.
certbot_install_from_source: no
certbot_repo: https://github.com/certbot/certbot.git
certbot_version: master
certbot_keep_updated: yes
# Where to put Certbot when installing from source.
certbot_dir: /opt/certbot
-2
View File
@@ -1,2 +0,0 @@
---
# TODO
+13 -4
View File
@@ -3,22 +3,31 @@ dependencies: []
galaxy_info:
author: geerlingguy
description: "Certbot (for Let's Encrypt) for RHEL/CentOS and Debian/Ubuntu."
description: "Installs and configures Certbot (for Let's Encrypt)."
company: "Midwestern Mac, LLC"
license: "license (BSD, MIT)"
min_ansible_version: 1.8
min_ansible_version: 2.4
platforms:
- name: EL
versions:
- 6
- 7
- name: Fedora
versions:
- all
- name: Ubuntu
versions:
- all
- all
- name: Debian
versions:
- all
- all
galaxy_tags:
- networking
- system
- web
- certbot
- letsencrypt
- encryption
- certificates
- ssl
- https
+23
View File
@@ -0,0 +1,23 @@
---
- name: Check if certificate already exists.
stat:
path: /etc/letsencrypt/live/{{ cert_item.domains | first }}/cert.pem
register: letsencrypt_cert
- name: Stop services to allow certbot to generate a cert.
service:
name: "{{ item }}"
state: stopped
when: not letsencrypt_cert.stat.exists
with_items: "{{ certbot_create_standalone_stop_services }}"
- name: Generate new certificate if one doesn't exist.
shell: "{{ certbot_create_command }}"
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 }}"
+8
View File
@@ -0,0 +1,8 @@
---
- name: Load a variable file based on the OS type, or a default if not found.
include_vars: "{{ item }}"
with_first_found:
- "{{ ansible_distribution }}-{{ ansible_distribution_version }}.yml"
- "{{ ansible_distribution }}.yml"
- "{{ ansible_os_family }}.yml"
- "default.yml"
+17
View File
@@ -0,0 +1,17 @@
---
- name: Clone Certbot into configured directory.
git:
repo: "{{ certbot_repo }}"
dest: "{{ certbot_dir }}"
version: "{{ certbot_version }}"
update: "{{ certbot_keep_updated }}"
force: yes
- name: Set Certbot script variable.
set_fact:
certbot_script: "{{ certbot_dir }}/certbot-auto"
- name: Ensure certbot-auto is executable.
file:
path: "{{ certbot_script }}"
mode: 0755
+7
View File
@@ -0,0 +1,7 @@
---
- name: Install Certbot.
package: "name={{ certbot_package }} state=present"
- name: Set Certbot script variable.
set_fact:
certbot_script: "{{ certbot_package }}"
+17 -10
View File
@@ -1,12 +1,19 @@
---
- name: Clone Certbot into configured directory.
git:
repo: "{{ certbot_repo }}"
dest: "{{ certbot_dir }}"
version: "{{ certbot_version }}"
update: "{{ certbot_keep_updated }}"
- import_tasks: include-vars.yml
- name: Ensure certbot-auto is executable.
file:
path: "{{ certbot_dir }}/certbot-auto"
mode: 0755
- import_tasks: install-with-package.yml
when: not certbot_install_from_source
- import_tasks: install-from-source.yml
when: certbot_install_from_source
- include_tasks: create-cert-standalone.yml
with_items: "{{ certbot_certs }}"
when:
- certbot_create_if_missing
- certbot_create_method == 'standalone'
loop_control:
loop_var: cert_item
- import_tasks: renew-cron.yml
when: certbot_auto_renew
+8
View File
@@ -0,0 +1,8 @@
---
- name: Add cron job for certbot renewal (if configured).
cron:
name: Certbot automatic renewal.
job: "{{ certbot_script }} renew {{ certbot_auto_renew_options }}"
minute: "{{ certbot_auto_renew_minute }}"
hour: "{{ certbot_auto_renew_hour }}"
user: "{{ certbot_auto_renew_user }}"
-15
View File
@@ -1,15 +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 ansible sudo
RUN yum clean all
# Disable requiretty
RUN sed -i -e 's/^\(Defaults\s*requiretty\)/#--- \1/' /etc/sudoers
# Install Ansible inventory file
RUN echo -e '[local]\nlocalhost ansible_connection=local' > /etc/ansible/hosts
CMD ["/usr/sbin/init"]
-27
View File
@@ -1,27 +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 epel-release
RUN yum -y install git ansible sudo
RUN yum clean all
# Disable requiretty
RUN sed -i -e 's/^\(Defaults\s*requiretty\)/#--- \1/' /etc/sudoers
# Install Ansible inventory file
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
+11
View File
@@ -0,0 +1,11 @@
# Ansible Role tests
To run the test playbook(s) in this directory:
1. Install and start Docker.
1. Download the test shim (see .travis.yml file for the URL) into `tests/test.sh`:
- `wget -O tests/test.sh https://gist.githubusercontent.com/geerlingguy/73ef1e5ee45d8694570f334be385e181/raw/`
1. Make the test shim executable: `chmod +x tests/test.sh`.
1. Run (from the role root directory) `distro=[distro] playbook=[playbook] ./tests/test.sh`
If you don't want the container to be automatically deleted after the test playbook is run, add the following environment variables: `cleanup=false container_id=$(date +%s)`
+3
View File
@@ -0,0 +1,3 @@
---
- src: geerlingguy.git
- src: geerlingguy.nginx
+23
View File
@@ -0,0 +1,23 @@
---
- hosts: all
vars:
certbot_install_from_source: yes
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
+178
View File
@@ -0,0 +1,178 @@
---
# To run:
# 1. Ensure Ansible and Boto are installed (pip install ansible boto).
# 2. Ensure you have AWS credentials stored where Boto can find them, and they
# are under the profile 'mm'.
# 3. Ensure you have a pubkey available at ~/.ssh/id_rsa.pub.
# 3. Run the playbook: ansible-playbook test-standalone-nginx-aws.yml
# Play 1: Provision EC2 instance and A record.
- hosts: localhost
connection: local
gather_facts: no
tasks:
- name: Configure EC2 Security Group.
ec2_group:
profile: mm
name: certbot_test_http
description: HTTP security group for Certbot testing.
region: "us-east-1"
state: present
rules:
- proto: tcp
from_port: 80
to_port: 80
cidr_ip: 0.0.0.0/0
- proto: tcp
from_port: 443
to_port: 443
cidr_ip: 0.0.0.0/0
- proto: tcp
from_port: 22
to_port: 22
cidr_ip: 0.0.0.0/0
rules_egress: []
- name: Add EC2 Key Pair.
ec2_key:
profile: mm
region: "us-east-1"
name: certbot_test
key_material: "{{ item }}"
with_file: ~/.ssh/id_rsa.pub
- name: Provision EC2 instance.
ec2:
profile: mm
key_name: certbot_test
instance_tags:
Name: "certbot-standalone-nginx-test"
group: ['default', 'certbot_test_http']
instance_type: t2.micro
image: ami-02e98f78 # CentOS Linux 7 x86_64 HVM EBS
region: "us-east-1"
wait: yes
wait_timeout: 500
exact_count: 1
count_tag:
Name: "certbot-standalone-nginx-test"
register: created_instance
- name: Add A record for the new EC2 instance IP in Route53.
route53:
profile: mm
command: create
zone: servercheck.in
record: certbot-test.servercheck.in
type: A
ttl: 300
value: "{{ created_instance.tagged_instances.0.public_ip }}"
wait: yes
overwrite: yes
- name: Add EC2 instance to inventory groups.
add_host:
name: "certbot-test.servercheck.in"
groups: "aws,aws_nginx"
ansible_ssh_user: centos
host_key_checking: False
when: created_instance.tagged_instances.0.id is defined
# Play 2: Configure EC2 instance with Certbot and Nginx.
- hosts: aws_nginx
gather_facts: yes
become: yes
vars:
certbot_admin_email: https@servercheck.in
certbot_create_if_missing: yes
certbot_create_standalone_stop_services: []
certbot_certs:
- domains:
- certbot-test.servercheck.in
nginx_vhosts:
- listen: "443 ssl http2"
server_name: "certbot-test.servercheck.in"
root: "/usr/share/nginx/html"
index: "index.html index.htm"
state: "present"
template: "{{ nginx_vhost_template }}"
filename: "certbot_test.conf"
extra_parameters: |
ssl_certificate /etc/letsencrypt/live/certbot-test.servercheck.in/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/certbot-test.servercheck.in/privkey.pem;
ssl_protocols TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
pre_tasks:
- name: Update apt cache.
apt: update_cache=yes cache_valid_time=600
when: ansible_os_family == 'Debian'
changed_when: false
- name: Install dependencies (RedHat).
yum: name={{ item }} state=present
when: ansible_os_family == 'RedHat'
with_items:
- cronie
- epel-release
- name: Install cron (Debian).
apt: name=cron state=present
when: ansible_os_family == 'Debian'
roles:
- geerlingguy.certbot
- geerlingguy.nginx
tasks:
- name: Flush handlers in case any configs have changed.
meta: flush_handlers
- name: Test secure connection to SSL domain.
uri:
url: https://certbot-test.servercheck.in/
status_code: 200
delegate_to: localhost
become: no
# Play 3: Tear down EC2 instance and A record.
- hosts: localhost
connection: local
gather_facts: no
tasks:
- name: Destroy EC2 instance.
ec2:
profile: mm
instance_ids: ["{{ created_instance.tagged_instances.0.id }}"]
region: "us-east-1"
state: absent
wait: yes
wait_timeout: 500
- name: Delete Security Group.
ec2_group:
profile: mm
name: certbot_test_http
region: "us-east-1"
state: absent
- name: Delete Key Pair.
ec2_key:
profile: mm
name: certbot_test
region: "us-east-1"
state: absent
- name: Delete Route53 record.
route53:
profile: mm
state: delete
zone: servercheck.in
record: certbot-test.servercheck.in
type: A
ttl: 300
# See: https://github.com/ansible/ansible/pull/32297
value: []
+17
View File
@@ -1,5 +1,22 @@
---
- 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 dependencies (RedHat).
yum: name={{ item }} state=present
when: ansible_os_family == 'RedHat'
with_items:
- cronie
- epel-release
- name: Install cron (Debian).
apt: name=cron state=present
when: ansible_os_family == 'Debian'
roles:
- role_under_test
+1
View File
@@ -0,0 +1 @@
certbot_package: letsencrypt
+2
View File
@@ -0,0 +1,2 @@
---
certbot_package: certbot