diff options
Diffstat (limited to 'services.yml')
-rw-r--r-- | services.yml | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/services.yml b/services.yml new file mode 100644 index 0000000..9dc1926 --- /dev/null +++ b/services.yml @@ -0,0 +1,128 @@ +- name: ship setup + hosts: all + gather_facts: no + vars: + user: "{{ '$USER' | expandvars }}" + data: "{{ '$HOME/services' | expandvars }}" + + # podman-rootless + # + # * using native overflay fs support (no fuse) + # - at least kernel version 5.13 + # - podman info -f '{{.Store.GraphDriverName}}' + # -> "overlay" + # - podman info -f '{{index .Store.GraphStatus "Native Overlay Diff"}}' + # -> true + # - if configured with different storage driver before may need to run + # podman system reset # deletes every image/container/.. with old driver + # - cat .local/share/containers/storage/overlay/.has-mount-program + # -> false + # + # * configure storage driver + # > cat .config/containers/storage.conf + # [storage] + # driver = "overlay" + + tasks: + + # -- LINGER ---------------------------------------------------------------- + + # Enable lingering for user. A user manager is spawned for the user at boot + # and kept around after logouts. This allows users who are not logged in to + # run long-running services. + - name: enable-linger + become: true + command: loginctl enable-linger {{ user }} + args: + # Command is not re-run if following file exits. + # https://docs.ansible.com/ansible/latest/collections/ansible/builtin/command_module.html#parameter-creates + creates: "/var/lib/systemd/linger/{{ user }}" + + # -- COPY FILES ------------------------------------------------------------ + + - name: copy-files + ansible.builtin.copy: + src: "{{ item }}" + dest: "{{ data }}" + mode: preserve + loop: + - ftp + - mosquitto + + # -- FTP SERVER ------------------------------------------------------------ + + - name: build-podman-ftp + containers.podman.podman_image: + name: ftp + path: "{{ data }}/ftp" + force: true + register: ftp_build + + - name: run-podman-ftp + containers.podman.podman_container: + name: ftp + image: ftp + network: host + volumes: + - "{{ data }}/ftp/inbox:/inbox" + command: python3 -m pyftpdlib --write -d /inbox -u pleb -P moose + recreate: "{{ ftp_build.changed }}" + + # -- MOSQUITTO SERVER ------------------------------------------------------ + + # Use `mosquitto_sub -t '#'` to subscribe to all topics. + - name: run-podman-mosquitto + containers.podman.podman_container: + name: mosquitto + image: docker.io/eclipse-mosquitto + ports: + - "1883:1883/tcp" + volumes: + - "{{ data }}/mosquitto/mosquitto.conf:/mosquitto/config/mosquitto.conf" + + # -- HOME ASSISTANT -------------------------------------------------------- + + - name: add-user-to-group + become: true + user: + name: "{{ user }}" + groups: dialout + append: yes + + - name: run-podman-home-assistant + containers.podman.podman_container: + name: homeassistant + image: ghcr.io/home-assistant/home-assistant:stable + network: host + # Keep groups, eg dialout for ttyUSB0. + group_add: keep-groups + volumes: + - "{{ data }}/home-assistant/config:/config" + - "/etc/localtime:/etc/localtime:ro" + device: + - "/dev/ttyUSB0:/dev/ttyUSB0" + + # -- USER SYSTEMD UNITS ---------------------------------------------------- + + - name: generate-user-systemd-units + containers.podman.podman_generate_systemd: + name: "{{ item }}" + dest: ~/.config/systemd/user/ + restart_policy: on-failure + restart_sec: 10 + loop: + - ftp + - mosquitto + - homeassistant + + - name: enable-user-systemd-units + ansible.builtin.systemd: + name: "container-{{ item }}" + scope: user + daemon_reload: true + #state: started + enabled: true + loop: + - ftp + - mosquitto + - homeassistant |