diff --git a/ansible/ansible.cfg b/ansible/ansible.cfg new file mode 100644 index 0000000..d47e70d --- /dev/null +++ b/ansible/ansible.cfg @@ -0,0 +1,5 @@ +[defaults] +remote_user=admin +become=True +roles_path=galaxy_roles/ +vault_password_file=./.vault_pass \ No newline at end of file diff --git a/ansible/galaxy_roles/caddy-ansible/.ansible-lint b/ansible/galaxy_roles/caddy-ansible/.ansible-lint new file mode 100644 index 0000000..f239a87 --- /dev/null +++ b/ansible/galaxy_roles/caddy-ansible/.ansible-lint @@ -0,0 +1,3 @@ +--- +skip_list: + - 'role-name' # Role name caddy-ansible does not match `^[a-z][a-z0-9_]+$` pattern diff --git a/ansible/galaxy_roles/caddy-ansible/.github/workflows/ci.yml b/ansible/galaxy_roles/caddy-ansible/.github/workflows/ci.yml new file mode 100644 index 0000000..ce6d43f --- /dev/null +++ b/ansible/galaxy_roles/caddy-ansible/.github/workflows/ci.yml @@ -0,0 +1,49 @@ +--- +name: CI +'on': + pull_request: + push: + branches: + - master + schedule: + - cron: "30 7 * * 3" + +defaults: + run: + working-directory: 'caddy_ansible.caddy_ansible' + +jobs: + molecule: + name: Molecule + runs-on: ubuntu-latest + strategy: + matrix: + distro: + - centos8 + - centos7 + - fedora29 + - ubuntu2004 + - ubuntu1804 + - debian10 + - debian9 + + steps: + - name: Check out the codebase. + uses: actions/checkout@v2 + with: + path: 'caddy_ansible.caddy_ansible' + + - name: Set up Python 3. + uses: actions/setup-python@v2 + with: + python-version: '3.x' + + - name: Install test dependencies. + run: pip3 install ansible ansible-lint yamllint molecule[docker] pytest testinfra + + - name: Run Molecule tests. + run: molecule test + env: + PY_COLORS: '1' + ANSIBLE_FORCE_COLOR: '1' + MOLECULE_DISTRO: ${{ matrix.distro }} diff --git a/ansible/galaxy_roles/caddy-ansible/.gitignore b/ansible/galaxy_roles/caddy-ansible/.gitignore new file mode 100644 index 0000000..2f1ab8f --- /dev/null +++ b/ansible/galaxy_roles/caddy-ansible/.gitignore @@ -0,0 +1,4 @@ +.vagrant +*.retry +.molecule +__pycache__/ diff --git a/ansible/galaxy_roles/caddy-ansible/.yamllint b/ansible/galaxy_roles/caddy-ansible/.yamllint new file mode 100644 index 0000000..a3dbc38 --- /dev/null +++ b/ansible/galaxy_roles/caddy-ansible/.yamllint @@ -0,0 +1,6 @@ +--- +extends: default +rules: + line-length: + max: 120 + level: warning diff --git a/ansible/galaxy_roles/caddy-ansible/LICENSE b/ansible/galaxy_roles/caddy-ansible/LICENSE new file mode 100644 index 0000000..ee34ccb --- /dev/null +++ b/ansible/galaxy_roles/caddy-ansible/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2015 Lorenz Bischof + +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. diff --git a/ansible/galaxy_roles/caddy-ansible/README.md b/ansible/galaxy_roles/caddy-ansible/README.md new file mode 100644 index 0000000..cea7637 --- /dev/null +++ b/ansible/galaxy_roles/caddy-ansible/README.md @@ -0,0 +1,213 @@ +[![Build Status](https://travis-ci.org/caddy-ansible/caddy-ansible.svg?branch=master)](https://travis-ci.org/caddy-ansible/caddy-ansible) +[![Galaxy Role](https://img.shields.io/badge/ansible--galaxy-caddy-blue.svg)](https://galaxy.ansible.com/caddy_ansible/caddy_ansible/) + +# Caddy Ansible Role + + + +- [Dependencies](#dependencies) +- [Role Variables](#role-variables) + * [The Caddyfile](#the-caddyfile) + * [The OS to download caddy for](#the-os-to-download-caddy-for) + * [Auto update Caddy?](#auto-update-caddy) + * [Additional Available Packages](#additional-available-packages) + * [Use `setcap`?](#use-setcap) + * [Use systemd capabilities controls](#use-systemd-capabilities-controls) + * [Add additional environment variables](#add-additional-environment-variables) + * [Use additional CLI arguments](#use-additional-cli-arguments) + * [Use a GitHub OAuth token to request the list of caddy releases](#use-a-github-oauth-token-to-request-the-list-of-caddy-releases) +- [Example Playbooks](#example-playbooks) +- [Debugging](#debugging) +- [Contributing](#contributing) + + + +This role installs and configures the caddy web server. The user can specify any http configuration parameters they wish to apply their site. Any number of sites can be added with configurations of your choice. + +## Dependencies + +None + +## Role Variables + +### The Caddyfile + +See [Caddyfile docs](https://caddyserver.com/docs/caddyfile). Notice the `|` used to include a multi-line string. You may set `caddy_conf_filename` to `config.json` to use json format. + +default: + +```yaml +caddy_conf_filename: Caddyfile +caddy_config: | + http://localhost:2020 + respond "Hello, world!" +``` + +If you wish to use a template for the config you can do this: + +```yaml +caddy_config: "{{ lookup('template', 'templates/Caddyfile.j2') }}" +``` + +### The OS to download caddy for + +default: + +```yaml +caddy_os: linux +``` + +### Auto update Caddy? + +default: + +```yaml +caddy_update: true +``` + +### Additional Available Packages + +Changing this variable will reinstall Caddy with the new packages if `caddy_update` is enabled. Check https://caddyserver.com/download for available packages. + +default: + +```yaml +caddy_packages: [] +``` + +### Use `setcap`? + +This allows Caddy to open a low port (under 1024 - e.g. 80, 443). + +default: + +```yaml +caddy_setcap: true +``` + +### Use systemd capabilities controls + +default: + +```yaml +caddy_systemd_capabilities_enabled: false +caddy_systemd_capabilities: "CAP_NET_BIND_SERVICE" +``` + +NOTE: This feature requires systemd v229 or newer and might be needed in addition to `caddy_setcap: yes`. + +Supported: + +* Debian 9 (stretch) +* Fedora 25 +* Ubuntu 16.04 (xenial) + +RHEL/CentOS has no release that supports systemd capability controls at this time. + +### Add additional environment variables + +Add environment variables to the systemd script. + +default: + +```yaml +caddy_environment_variables: {} +``` + +Example usage: + +```yaml +caddy_environment_variables: + FOO: bar + SECONDVAR: spam +``` + +### Use additional CLI arguments + +default: + +```yaml +caddy_additional_args: "" +``` + +Example for LetsEncrypt staging: + +```yaml +caddy_additional_args: "-ca https://acme-staging.api.letsencrypt.org/directory" +``` + +### Use a GitHub OAuth token to request the list of caddy releases + +This role uses the GitHub releases list to check when a new version is available. [GitHub has some fairly agressive rate-limiting](https://developer.github.com/v3/#rate-limiting) which can cause failures. You can set your GitHub token to increase the limits for yourself when running the role (e.g. if deploying many servers behind a NAT or running this role repeatedly as part of a CI process). + +default: + +```yaml +caddy_github_token: "" +``` + +## Example Playbooks + +```yaml +--- +- hosts: all + become: yes + roles: + - role: caddy_ansible.caddy_ansible + caddy_config: | + files.example.com + encode gzip + file_server browse { + root /home/caddy/ + } +``` + +Example with DigitalOcean DNS for TLS: + +```yaml +--- +- hosts: all + roles: + - role: caddy_ansible.caddy_ansible + caddy_environment_variables: + DO_AUTH_TOKEN: "your-token-here" + caddy_systemd_capabilities_enabled: true + caddy_systemd_network_dependency: false + caddy_packages: ["github.com/caddy-dns/lego-deprecated"] + caddy_config: | + nextcloud.example.com { + log + + reverse_proxy http://localhost:8080 { + header_up Host {http.request.host} + header_up X-Real-IP {http.request.remote.host} + header_up X-Forwarded-For {http.request.remote.host} + header_up X-Forwarded-Port {http.request.port} + header_up X-Forwarded-Proto {http.request.scheme} + } + + tls webmaster@example.com { + dns lego_deprecated digitalocean + } + } +``` + +## Debugging + +If the service fails to start you can figure out why by looking at the output of Caddy. + +```bash +systemctl status caddy -l +``` + +If something doesn't seem right, open an issue! + +## Contributing + +Pull requests are welcome. Please test your changes beforehand with vagrant: + +```bash +vagrant up +vagrant provision # (since it already provisioned there should be no changes here) +vagrant destroy +``` diff --git a/ansible/galaxy_roles/caddy-ansible/Vagrantfile b/ansible/galaxy_roles/caddy-ansible/Vagrantfile new file mode 100644 index 0000000..e10a698 --- /dev/null +++ b/ansible/galaxy_roles/caddy-ansible/Vagrantfile @@ -0,0 +1,49 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +Vagrant.configure(2) do |config| + config.vm.define "buster" do |buster| + buster.vm.box = "debian/buster64" + end + + config.vm.define "bionic" do |bionic| + bionic.vm.box = "bento/ubuntu-18.04" + end + + config.vm.define "focal" do |focal| + focal.vm.box = "bento/ubuntu-20.04" + end + + config.vm.define "centos7" do |centos7| + centos7.vm.box = "bento/centos-7.6" + end + + config.vm.define "fedora32" do |fedora32| + fedora32.vm.box = "bento/fedora-32" + end + + config.vm.provision "ansible" do |ansible| + ansible.playbook = 'tests/playbook.yml' + ansible.verbose = true + end + + $script = <