commit ced099de32564b1c4fb305ad9d0663fb3f904760
Author: Leo Maroni <git@em0lar.de>
Date:   Sat Jan 2 22:56:33 2021 +0100

    Initial commit

diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..3c0c6fb
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2020 Leo 'em0lar' Maroni
+
+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/defaults/main.yml b/defaults/main.yml
new file mode 100644
index 0000000..39c3c59
--- /dev/null
+++ b/defaults/main.yml
@@ -0,0 +1,3 @@
+---
+caddy_config_sites_directory: "/etc/caddy/sites.d"
+caddy_config_sites_clear: false
diff --git a/handlers/main.yml b/handlers/main.yml
new file mode 100644
index 0000000..6865b95
--- /dev/null
+++ b/handlers/main.yml
@@ -0,0 +1,5 @@
+---
+- name: Reload caddy
+  systemd:
+    name: "caddy.service"
+    state: reloaded
diff --git a/meta/main.yml b/meta/main.yml
new file mode 100644
index 0000000..aef7da6
--- /dev/null
+++ b/meta/main.yml
@@ -0,0 +1,53 @@
+galaxy_info:
+  role_name: caddy
+  author: Leo 'em0lar' Maroni
+  description: Ansible role for installing and configuring caddy
+  # company: your company (optional)
+
+  # If the issue tracker for your role is not on github, uncomment the
+  # next line and provide a value
+  # issue_tracker_url: http://example.com/issue/tracker
+
+  # Choose a valid license ID from https://spdx.org - some suggested licenses:
+  # - BSD-3-Clause (default)
+  # - MIT
+  # - GPL-2.0-or-later
+  # - GPL-3.0-only
+  # - Apache-2.0
+  # - CC-BY-4.0
+  license: MIT
+
+  min_ansible_version: 2.1
+
+  # If this a Container Enabled role, provide the minimum Ansible Container version.
+  # min_ansible_container_version:
+
+  #
+  # Provide a list of supported platforms, and for each platform a list of versions.
+  # If you don't wish to enumerate all versions for a particular platform, use 'all'.
+  # To view available platforms and versions (or releases), visit:
+  # https://galaxy.ansible.com/api/v1/platforms/
+  #
+  platforms:
+    - name: Debian
+      versions:
+        - all
+    - name: Ubuntu
+      versions:
+        - all
+
+  galaxy_tags:
+    - caddy
+    - caddyserver
+    - http
+    - web
+    # List tags for your role here, one per line. A tag is a keyword that describes
+    # and categorizes the role. Users find roles by searching for tags. Be sure to
+    # remove the '[]' above, if you add tags to this list.
+    #
+    # NOTE: A tag is limited to a single word comprised of alphanumeric characters.
+  #       Maximum 20 tags per role.
+
+dependencies: []
+# List your role dependencies here, one per line. Be sure to remove the '[]' above,
+# if you add dependencies to this list.
diff --git a/tasks/configuration.yml b/tasks/configuration.yml
new file mode 100644
index 0000000..b85c7e2
--- /dev/null
+++ b/tasks/configuration.yml
@@ -0,0 +1,36 @@
+---
+- name: Create Caddyfile
+  copy:
+    src: "{{ caddy_config_file }}"
+    dest: "/etc/caddy/Caddyfile"
+    owner: "caddy"
+    mode: 0640
+  notify:
+    - Reload caddy
+
+- name: Clear sites.d directory before adding net configurations
+  file:
+    path: "{{ caddy_config_sites_directory }}"
+    owner: "caddy"
+    group: "caddy"
+    state: absent
+  when: caddy_config_sites_paths is defined and caddy_config_sites_clear
+
+- name: Add sites.d directory
+  file:
+    path: "{{ caddy_config_sites_directory }}"
+    owner: "caddy"
+    group: "caddy"
+    state: directory
+  when: caddy_config_sites_paths is defined
+
+- name: Template site configurations
+  template:
+    src: "{{ item }}"
+    dest: "{{ caddy_config_sites_directory }}"
+    owner: "caddy"
+    group: "caddy"
+  with_fileglob: "{{ caddy_config_sites_paths }}"
+  when: caddy_config_sites_paths is defined
+  notify:
+    - Reload caddy
diff --git a/tasks/install.yml b/tasks/install.yml
new file mode 100644
index 0000000..1baaff2
--- /dev/null
+++ b/tasks/install.yml
@@ -0,0 +1,22 @@
+---
+- name: Add apt signing key for caddy apt repository
+  apt_key:
+    url: "https://dl.cloudsmith.io/public/caddy/stable/cfg/gpg/gpg.155B6D79CA56EA34.key"
+    state: present
+
+- name: Add caddy apt repository
+  apt_repository:
+    repo: "deb https://dl.cloudsmith.io/public/caddy/stable/deb/debian any-version main"
+    state: present
+
+- name: Add caddy apt source repository
+  apt_repository:
+    repo: "deb-src https://dl.cloudsmith.io/public/caddy/stable/deb/debian any-version main"
+    state: present
+
+- name: Install caddy apt package
+  apt:
+    name: "caddy"
+    state: present
+
+
diff --git a/tasks/main.yml b/tasks/main.yml
new file mode 100644
index 0000000..eee1e65
--- /dev/null
+++ b/tasks/main.yml
@@ -0,0 +1,4 @@
+---
+- include_tasks: "install.yml"
+- include_tasks: "configuration.yml"
+