|
| 1 | +--- |
| 2 | +- hosts: virtualmachines |
| 3 | + vars_files: |
| 4 | + - vars.yaml |
| 5 | + become: yes |
| 6 | + tasks: |
| 7 | + # smoke test and essential dependencies |
| 8 | + - name: ping |
| 9 | + ansible.builtin.ping: |
| 10 | + - name: essentials |
| 11 | + ansible.builtin.apt: |
| 12 | + update_cache: yes |
| 13 | + name: |
| 14 | + - gcc |
| 15 | + - git |
| 16 | + - rclone |
| 17 | + - vim |
| 18 | + state: present |
| 19 | + |
| 20 | + # caddy |
| 21 | + - name: add caddy key |
| 22 | + ansible.builtin.apt_key: |
| 23 | + id: 65760C51EDEA2017CEA2CA15155B6D79CA56EA34 |
| 24 | + url: https://dl.cloudsmith.io/public/caddy/stable/gpg.key |
| 25 | + keyring: /etc/apt/trusted.gpg.d/caddy-stable.gpg |
| 26 | + state: present |
| 27 | + - name: add caddy deb repository |
| 28 | + ansible.builtin.apt_repository: |
| 29 | + repo: deb [signed-by=/etc/apt/trusted.gpg.d/caddy-stable.gpg] https://dl.cloudsmith.io/public/caddy/stable/deb/debian any-version main |
| 30 | + - name: add caddy deb-src repository |
| 31 | + ansible.builtin.apt_repository: |
| 32 | + repo: deb [signed-by=/etc/apt/trusted.gpg.d/caddy-stable.gpg] https://dl.cloudsmith.io/public/caddy/stable/deb/debian any-version main |
| 33 | + - name: install caddy |
| 34 | + ansible.builtin.apt: |
| 35 | + update_cache: yes |
| 36 | + name: caddy |
| 37 | + - name: caddyfile |
| 38 | + ansible.builtin.template: |
| 39 | + src: illich.caddy.j2 |
| 40 | + dest: /etc/caddy/illich.caddy |
| 41 | + owner: root |
| 42 | + group: root |
| 43 | + mode: '0644' |
| 44 | + |
| 45 | + # deploy user and directory |
| 46 | + - name: www directory |
| 47 | + ansible.builtin.file: |
| 48 | + path: /var/www |
| 49 | + state: directory |
| 50 | + mode: '0755' |
| 51 | + - name: create user |
| 52 | + ansible.builtin.user: |
| 53 | + name: deploy |
| 54 | + password: "" |
| 55 | + shell: /bin/bash |
| 56 | + groups: |
| 57 | + - sudo |
| 58 | + - www-data |
| 59 | + append: yes |
| 60 | + createhome: yes |
| 61 | + skeleton: '/etc/skel' |
| 62 | + generate_ssh_key: yes |
| 63 | + ssh_key_type: 'ed25519' |
| 64 | + - name: www ownership |
| 65 | + ansible.builtin.file: |
| 66 | + path: /var/www |
| 67 | + owner: deploy |
| 68 | + group: www-data |
| 69 | + recurse: yes |
| 70 | + |
| 71 | + # uv |
| 72 | + - name: uv |
| 73 | + ansible.builtin.shell: |
| 74 | + cmd: curl -LsSf https://astral.sh/uv/0.9.17/install.sh | sh |
| 75 | + become_user: deploy |
| 76 | + |
| 77 | + # repository |
| 78 | + - name: clone |
| 79 | + ansible.builtin.git: |
| 80 | + repo: https://github.com/mataroablog/illich |
| 81 | + dest: /var/www/illich |
| 82 | + version: main |
| 83 | + accept_hostkey: true |
| 84 | + become_user: deploy |
| 85 | + |
| 86 | + # systemd |
| 87 | + - name: systemd template |
| 88 | + ansible.builtin.template: |
| 89 | + src: illich.service.j2 |
| 90 | + dest: /etc/systemd/system/illich.service |
| 91 | + owner: root |
| 92 | + group: root |
| 93 | + mode: '0644' |
| 94 | + - name: systemd reload |
| 95 | + ansible.builtin.systemd: |
| 96 | + daemon_reload: true |
| 97 | + - name: systemd enable |
| 98 | + ansible.builtin.systemd: |
| 99 | + name: illich |
| 100 | + enabled: yes |
| 101 | + - name: systemd start |
| 102 | + ansible.builtin.systemd: |
| 103 | + name: illich |
| 104 | + state: restarted |
| 105 | + |
| 106 | + # deployment specific |
| 107 | + - name: collectstatic |
| 108 | + ansible.builtin.shell: |
| 109 | + cmd: | |
| 110 | + source $HOME/.local/bin/env |
| 111 | + uv run manage.py collectstatic --no-input |
| 112 | + chdir: /var/www/illich |
| 113 | + args: |
| 114 | + executable: /bin/bash |
| 115 | + become_user: deploy |
| 116 | + - name: migrations |
| 117 | + ansible.builtin.shell: |
| 118 | + cmd: | |
| 119 | + source $HOME/.local/bin/env |
| 120 | + uv run manage.py migrate --no-input |
| 121 | + chdir: /var/www/illich |
| 122 | + args: |
| 123 | + executable: /bin/bash |
| 124 | + become_user: deploy |
| 125 | + - name: gunicorn restart |
| 126 | + ansible.builtin.systemd: |
| 127 | + name: illich |
| 128 | + state: restarted |
| 129 | + - name: caddy restart |
| 130 | + ansible.builtin.systemd: |
| 131 | + name: caddy |
| 132 | + state: restarted |
0 commit comments