From 55b29c38ed09def2c0bf996d6c21c6734724ea67 Mon Sep 17 00:00:00 2001 From: Mateo Date: Tue, 16 Jul 2024 14:32:10 +0200 Subject: [PATCH] Caddy install --- tasks/install_caddy.yml | 40 ++++++++++++++++++++++++++++++++++++++++ templates/Caddyfile.j2 | 26 ++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 tasks/install_caddy.yml create mode 100644 templates/Caddyfile.j2 diff --git a/tasks/install_caddy.yml b/tasks/install_caddy.yml new file mode 100644 index 0000000..f6b77d3 --- /dev/null +++ b/tasks/install_caddy.yml @@ -0,0 +1,40 @@ +- name: Install & configure Caddy + hosts: athelas + become: true + tasks: + + - name: Add Caddy GPG Key + ansible.builtin.apt_key: + url: https://dl.cloudsmith.io/public/caddy/stable/gpg.key + state: present + + - name: Add Caddy Repo + ansible.builtin.apt_repository: + repo: deb [signed-by=/usr/share/keyrings/caddy-stable-archive-keyring.gpg] https://dl.cloudsmith.io/public/caddy/stable/deb/debian any-version main + state: present + + - name: Add Caddy Src Repo + ansible.builtin.apt_repository: + repo: deb-src [signed-by=/usr/share/keyrings/caddy-stable-archive-keyring.gpg] https://dl.cloudsmith.io/public/caddy/stable/deb/debian any-version main + state: present + + - name: Install Caddy + ansible.builtin.package: + name: caddy + + - name: Creating webserver root folder + ansible.builtin.file: + path: /var/www/html/index.html + state: directory + group: caddy + owner: caddy + + - name: Editing Caddyfile + ansible.builtin.template: + src: ~/ansible/templates/Caddyfile.j2 + dest: /etc/caddy/Caddyfile + + - name: Reload Caddy service + ansible.builtin.service: + name: caddy + state: reloaded diff --git a/templates/Caddyfile.j2 b/templates/Caddyfile.j2 new file mode 100644 index 0000000..5c942aa --- /dev/null +++ b/templates/Caddyfile.j2 @@ -0,0 +1,26 @@ +# The Caddyfile is an easy way to configure your Caddy web server. +# +# Unless the file starts with a global options block, the first +# uncommented line is always the address of your site. +# +# To use your own domain name (with automatic HTTPS), first make +# sure your domain's A/AAAA DNS records are properly pointed to +# this machine's public IP, then replace ":80" below with your +# domain name. + +athelas.motysten.fr { + # Set this path to your site's directory. + root * /var/www/html + + # Enable the static file server. + file_server + + # Another common task is to set up a reverse proxy: + # reverse_proxy localhost:8080 + + # Or serve a PHP site through php-fpm: + # php_fastcgi localhost:9000 +} + +# Refer to the Caddy docs for more information: +# https://caddyserver.com/docs/caddyfile