-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit fe406c9
Showing
30 changed files
with
939 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[flake8] | ||
ignore = E501,E128 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
### Ansible ### | ||
*.retry | ||
|
||
### Python ### | ||
# Byte-compiled / optimized / DLL files | ||
.pytest_cache | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
### Molecule ### | ||
.tox | ||
.cache | ||
.molecule | ||
.vagrant |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
|
||
language: python | ||
python: "2.7" | ||
|
||
sudo: required | ||
|
||
# Enable the docker service | ||
services: | ||
- docker | ||
|
||
# Replace aufs with the vfs docker storage driver | ||
# to prevent systemd to fail starting docker in docker. | ||
before_install: | ||
- sudo sed -i 's|DOCKER_OPTS=.*|DOCKER_OPTS="-H tcp://127.0.0.1:2375 -H unix:///var/run/docker.sock --storage-driver vfs"|g' /etc/default/docker | ||
- sudo service docker restart | ||
- docker info | ||
|
||
# Install tox | ||
install: | ||
- pip install tox-travis | ||
|
||
# Parallel testing of the supported Ansible versions | ||
env: | ||
matrix: | ||
- ANSIBLE=2.2 | ||
- ANSIBLE=2.3 | ||
- ANSIBLE=2.4 | ||
- ANSIBLE=2.5 | ||
|
||
# Tests all the scenarios | ||
script: | ||
- tox | ||
|
||
notifications: | ||
webhooks: https://galaxy.ansible.com/api/v1/notifications/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
extends: default | ||
|
||
rules: | ||
braces: | ||
max-spaces-inside: 1 | ||
level: error | ||
brackets: | ||
max-spaces-inside: 1 | ||
level: error | ||
line-length: disable | ||
# NOTE(retr0h): Templates no longer fail this lint rule. | ||
# Uncomment if running old Molecule templates. | ||
# truthy: disable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 Andrea Tosatto | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
Ansible Role: Caddy | ||
=================== | ||
|
||
[![Build Status](https://travis-ci.org/atosatto/ansible-caddy.svg?branch=master)](https://travis-ci.org/atosatto/ansible-caddy) | ||
[![Galaxy](https://img.shields.io/badge/galaxy-atosatto.caddy-blue.svg?style=flat-square)](https://galaxy.ansible.com/atosatto/caddy) | ||
|
||
Install and configure Caddy. | ||
|
||
Requirements | ||
------------ | ||
|
||
An Ansible 2.2 or higher installation.<br /> | ||
This role makes use of the Ansible `json_filter` that requires `jmespath` to be installed on the Ansible machine. | ||
See the `requirements.txt` file for further details on the specific version of `jmespath` required by the role. | ||
|
||
Role Variables | ||
-------------- | ||
|
||
Available variables are listed below, along with default values (see defaults/main.yml): | ||
|
||
caddy_release_tag: "latest" | ||
|
||
The Caddy release to be installed. | ||
By default, the latest release published at https://github.com/caddy/caddy/releases. | ||
|
||
caddy_user: "caddy" | ||
caddy_group: "caddy" | ||
|
||
Caddy system user and group. | ||
|
||
caddy_install_path: "/opt" | ||
|
||
Directory containing the downloaded Caddy release artifacts. | ||
|
||
caddy_bin_path: "/usr/local/bin" | ||
|
||
Directory to which the Caddy biyy will be symlinked. | ||
|
||
caddy_config_file: "/etc/caddy.conf" | ||
|
||
Path to the main Caddy configuration file. | ||
|
||
caddy_config_import_path: "/etc/caddy.conf.d" | ||
caddy_config_import_files: {} | ||
|
||
Directory including Caddy's additional configuration files to be imported in the `caddy_config_file` file. | ||
|
||
caddy_config_extra: "" | ||
|
||
Additional configuration to be injected into the `caddy_config_file` file. | ||
|
||
caddy_ssl_certificates_path: "/etc/ssl/caddy" | ||
|
||
Directory containing the SSL files generated by Caddy. | ||
|
||
caddy_listen_address: "127.0.0.1:9090" | ||
|
||
The Caddy listen ip address and port. | ||
|
||
caddy_web_root: "/var/www" | ||
|
||
Caddy HTTP server default Web folder. | ||
|
||
caddy_additional_cli_args: "" | ||
|
||
Additional command-line arguments to be added to the Caddy service unit. | ||
For the complete refence of the available CLI arguments please refer to the output | ||
of the `caddy --help` command. | ||
|
||
Dependencies | ||
------------ | ||
|
||
None. | ||
|
||
Example Playbooks | ||
----------------- | ||
|
||
$ cat playbook.yml | ||
- name: "Install and configure Caddy" | ||
hosts: all | ||
roles: | ||
- { role: atosatto.caddy } | ||
|
||
Testing | ||
------- | ||
|
||
Tests are automated with [Molecule](http://molecule.readthedocs.org/en/latest/). | ||
|
||
$ pip install tox | ||
|
||
To test all the scenarios run | ||
|
||
$ tox | ||
|
||
To run a custom molecule command | ||
|
||
$ tox -e py27-ansible23 -- molecule test -s caddy-latest | ||
|
||
License | ||
------- | ||
|
||
MIT | ||
|
||
Author Information | ||
------------------ | ||
|
||
Andrea Tosatto ([@\_hilbert\_](https://twitter.com/_hilbert_)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
|
||
# The Caddy release to be installed | ||
caddy_release_tag: "latest" | ||
|
||
# Caddy user and group | ||
caddy_user: "www-data" | ||
caddy_group: "www-data" | ||
|
||
# Directory containing the downloaded Caddy release | ||
caddy_install_path: "/opt" | ||
|
||
# Directory to which symlink the installed Caddy binary | ||
caddy_bin_path: "/usr/local/bin" | ||
|
||
# Caddy configuration file and directory | ||
caddy_config_file: "/etc/caddy.conf" | ||
|
||
# Caddy configuration import path and files | ||
caddy_config_import_path: "/etc/caddy.conf.d" | ||
caddy_config_import_files: {} | ||
|
||
# Additional configuration to be injected into the main caddy_config_file | ||
caddy_config_extra: "" | ||
|
||
# Directory containing the SSL files generated by Caddy | ||
caddy_ssl_certificates_path: "/etc/ssl/caddy" | ||
|
||
# Caddy listen address | ||
caddy_listen_address: "127.0.0.1:8080" | ||
|
||
# WebRoot for the Caddy HTTP server | ||
caddy_web_root: "/var/www" | ||
|
||
# Additional command-line arguments to be added to the Caddy unit | ||
caddy_additional_cli_args: "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"""Prometheus Jinja2 filters""" | ||
import re | ||
|
||
|
||
CADDY_SYSTEM = { | ||
'Linux': 'linux', | ||
'Darwin': 'darwin', | ||
'FreeBSD': 'freebsd', | ||
'OpenBSD': 'openbsd' | ||
} | ||
|
||
CADDY_ARCHITECTURE = { | ||
'x86_64': 'amd64', | ||
'i386': '386', | ||
'armv6l': 'armv6', | ||
'armv7l': 'armv7' | ||
} | ||
|
||
|
||
def caddy_release_build(hostvars, caddyrelease): | ||
|
||
architecture = hostvars['ansible_architecture'] | ||
system = hostvars['ansible_system'] | ||
|
||
return 'caddy_' + caddyrelease + '_' + CADDY_SYSTEM[system] + '_' + CADDY_ARCHITECTURE[architecture] | ||
|
||
|
||
class FilterModule(object): | ||
|
||
|
||
def filters(self): | ||
return { | ||
'caddy_release_build': caddy_release_build | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
|
||
- name: restart caddy | ||
service: | ||
name: caddy | ||
state: restarted | ||
|
||
- name: reload systemd and restart caddy | ||
command: systemctl daemon-reload | ||
notify: restart caddy | ||
tags: | ||
- skip_ansible_lint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--- | ||
|
||
galaxy_info: | ||
author: Andrea Tosatto | ||
description: Install and Configure Caddy | ||
issue_tracker_url: https://github.com/atosatto/ansible-caddy/issues | ||
license: MIT | ||
min_ansible_version: 2.2 | ||
|
||
platforms: | ||
- name: EL | ||
versions: | ||
- 7 | ||
- name: Ubuntu | ||
versions: | ||
- trusty | ||
- utopic | ||
- vivid | ||
- wily | ||
- xenial | ||
- name: Debian | ||
versions: | ||
- stretch | ||
- jessie | ||
|
||
galaxy_tags: | ||
- caddy | ||
- webserver | ||
- letsencypt | ||
- https | ||
- system | ||
|
||
dependencies: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
|
||
scenario: | ||
# Test the out-of-the-box installation of the latest Prometheus release | ||
name: caddy-latest | ||
|
||
driver: | ||
name: docker | ||
|
||
dependency: | ||
name: galaxy | ||
|
||
platforms: | ||
|
||
- name: centos-7 | ||
image: centos:7 | ||
dockerfile_tpl: centos-systemd | ||
|
||
- name: ubuntu-1604 | ||
image: ubuntu:16.04 | ||
dockerfile_tpl: debian-systemd | ||
|
||
- name: debian-9 | ||
image: debian:9 | ||
dockerfile_tpl: debian-systemd | ||
|
||
provisioner: | ||
name: ansible | ||
options: | ||
diff: True | ||
v: True | ||
playbooks: | ||
create: ../resources/create.yml | ||
destroy: ../resources/destroy.yml | ||
prepare: ../resources/prepare.yml | ||
lint: | ||
name: ansible-lint | ||
|
||
lint: | ||
name: yamllint | ||
|
||
verifier: | ||
name: testinfra | ||
options: | ||
vvv: True | ||
additional_files_or_dirs: | ||
- ../../resources/tests/ | ||
lint: | ||
name: flake8 # Will use the rules defined in .flake8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
|
||
- name: Install Caddy | ||
hosts: all | ||
roles: | ||
- { role: ansible-caddy } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import re | ||
import json | ||
import urllib2 | ||
|
||
|
||
caddy_last_release = re.sub('^v(.*)$', '\\1', | ||
json.loads(urllib2.urlopen("https://api.github.com/repos/mholt/caddy/releases/latest").read())["tag_name"]) | ||
caddy_last_artifact = "caddy_v" + caddy_last_release + "_linux_amd64" | ||
|
||
|
||
def test_caddy_binary(host): | ||
|
||
caddy = host.file('/usr/local/bin/caddy') | ||
assert caddy.exists | ||
assert caddy.is_symlink | ||
assert caddy.linked_to == '/opt/' + caddy_last_artifact + '/caddy' | ||
|
||
|
||
def test_caddy_release(host): | ||
|
||
cmd = host.run('/usr/local/bin/caddy --version') | ||
|
||
assert 'Caddy ' + caddy_last_release in (cmd.stdout + cmd.stderr) |
Oops, something went wrong.