--- - name: Basic Server setup hosts: all gather_facts: false tasks: - name: Change hostname ansible.builtin.hostname: name: "{{ inventory_hostname }}" - name: apt update ansible.builtin.apt: update_cache: true upgrade: yes - name: Install fish ansible.builtin.apt: name: "fish" state: present - name: "Change root's shell to fish" ansible.builtin.user: name: root shell: /usr/bin/fish - name: Install useful tools ansible.builtin.apt: name: "{{ item }}" state: present with_items: - htop - awscli - name: Install keyring packages ansible.builtin.apt: name: "{{ item }}" with_items: - debian-keyring - debian-archive-keyring - apt-transport-https - name: Add caddy keyrings ansible.builtin.shell: | set -euo pipefail rm -f /usr/share/keyrings/caddy-stable-archive-keyring.gpg curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg # todo: show ok/changed args: executable: /bin/bash - name: Add caddy repository ansible.builtin.get_url: url: "https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt" dest: "/etc/apt/sources.list.d/caddy-stable.list" mode: "u=rw,g=r,o=r" - name: Add the docker GPG key ansible.builtin.get_url: url: "https://download.docker.com/linux/ubuntu/gpg" dest: "/etc/apt/keyrings/docker.asc" mode: "u=r,g=r,o=r" - name: Add docker repository ansible.builtin.copy: dest: "/etc/apt/sources.list.d/docker.list" content: "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu jammy stable" - name: Install docker ansible.builtin.apt: name: "{{ item }}" state: present with_items: - docker-ce - docker-ce-cli - docker-compose-plugin - name: Ensure docker is started ansible.builtin.service: name: docker state: started - name: Install caddy ansible.builtin.apt: name: caddy state: present args: update_cache: true - name: Ensure caddy is started ansible.builtin.service: name: caddy state: started - name: Create debug html root ansible.builtin.file: path: /var/www/html/debug state: directory mode: "u=rwx,g=rx,o=rx" - name: Create debug webserver file ansible.builtin.copy: dest: /var/www/html/debug/index.html src: "../debug.html" mode: "u=rw,g=r,o=r" - name: Copy Caddyfile ansible.builtin.copy: dest: /etc/caddy/Caddyfile src: "../{{ inventory_hostname }}/Caddyfile" # TODO: Choose the right caddyfile depending on the server. mode: "u=rw,g=r,o=r" notify: - "Caddyfile changed" - name: Create /apps ansible.builtin.file: path: /apps state: directory mode: u=rwx,g=rx,o=rx - name: Copy docker-compose ansible.builtin.copy: dest: /apps/docker-compose.yml src: "../{{ inventory_hostname }}/docker-compose.yml" # TODO: choose the right directory mode: "u=r,g=r,o=r" handlers: - name: "Caddyfile changed" ansible.builtin.service: name: caddy state: reloaded