diff --git a/ansible/plays/backup.yaml b/ansible/plays/backup.yaml new file mode 100644 index 0000000..64bb371 --- /dev/null +++ b/ansible/plays/backup.yaml @@ -0,0 +1,68 @@ +- name: Setup Infra Meta Host + hosts: backup.unruhig.eu + gather_facts: false + tasks: + - name: Create user [backup] + become: true + ansible.builtin.user: + name: backup + comment: Used for receiving borg backups + shell: /bin/bash + create_home: true + state: present + generate_ssh_key: true + ssh_key_type: "ed25519" + ssh_key_file: ".ssh/storagebox" + - name: Create mount directory + become: true + become_user: backup + ansible.builtin.file: + path: "/home/backup/storagebox" + state: directory + - name: Create systemd user config directory + become: true + become_user: backup + ansible.builtin.file: + path: "/home/backup/.config/systemd/user" + state: directory + - name: Check if user is lingering + become: true + stat: + path: "/var/lib/systemd/linger/backup" + register: user_lingering + - name: Enable lingering for user if needed + become: true + command: "loginctl enable-linger backup" + when: + - not user_lingering.stat.exists + - name: Create mount unit + become: true + become_user: backup + ansible.builtin.template: + src: mount-storagebox.mount.j2 + dest: /home/backup/.config/systemd/user/var-home-backup-storagebox.mount + - name: Create automount unit + become: true + become_user: backup + ansible.builtin.template: + src: mount-storagebox.automount.j2 + dest: /home/backup/.config/systemd/user/var-home-backup-storagebox.automount + - name: Start storagebox Mount Service + become: true + become_user: backup + ansible.builtin.systemd: + name: var-home-backup-storagebox.mount + state: started + enabled: true + daemon_reload: true + scope: user + - name: enable storagebox automount Mount Unit + become: true + become_user: backup + ansible.builtin.systemd: + name: var-home-backup-storagebox.automount + enabled: true + scope: user + + +# vim: ft=yaml.ansible diff --git a/ansible/plays/templates/mount-storagebox.automount.j2 b/ansible/plays/templates/mount-storagebox.automount.j2 new file mode 100644 index 0000000..9b84623 --- /dev/null +++ b/ansible/plays/templates/mount-storagebox.automount.j2 @@ -0,0 +1,8 @@ +[Unit] +Description=storagebox automount + +[Automount] +Where=/var/home/backup/storagebox + +[Install] +WantedBy=multi-user.target diff --git a/ansible/plays/templates/mount-storagebox.mount.j2 b/ansible/plays/templates/mount-storagebox.mount.j2 new file mode 100644 index 0000000..8ec0485 --- /dev/null +++ b/ansible/plays/templates/mount-storagebox.mount.j2 @@ -0,0 +1,14 @@ +[Unit] +Description=Mount storagebox with sshfs +After=network-online.target +Wants=network-online.target + +[Install] +WantedBy=default.target + +[Mount] +What=u309229-sub6@u309229.your-storagebox.de: +Where=/var/home/backup/storagebox +Type=fuse.sshfs +Options=_netdev,reconnect,delay_connect,ServerAliveInterval=30,ServerAliveCountMax=5,x-systemd.automount,Port=23,IdentityFile=/var/home/backup/.ssh/storagebox +TimeoutSec=60