diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2018-12-26 11:02:22 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2018-12-26 11:02:22 +0100 |
commit | 37e93cced23e0ee726309e841b1dac19e9ccdac4 (patch) | |
tree | 8c692652c0a5fdbd0d95510dabd58c95e1805541 /ansible/roles/borg-client/tasks | |
parent | 72811f0f48cad07351ab5c5224616383a6920add (diff) | |
download | infra-37e93cced23e0ee726309e841b1dac19e9ccdac4.tar.gz infra-37e93cced23e0ee726309e841b1dac19e9ccdac4.tar.bz2 infra-37e93cced23e0ee726309e841b1dac19e9ccdac4.tar.xz infra-37e93cced23e0ee726309e841b1dac19e9ccdac4.zip |
o Working borg setup.
Diffstat (limited to 'ansible/roles/borg-client/tasks')
-rw-r--r-- | ansible/roles/borg-client/tasks/main.yml | 93 |
1 files changed, 90 insertions, 3 deletions
diff --git a/ansible/roles/borg-client/tasks/main.yml b/ansible/roles/borg-client/tasks/main.yml index 79a9406..a65ae3e 100644 --- a/ansible/roles/borg-client/tasks/main.yml +++ b/ansible/roles/borg-client/tasks/main.yml @@ -1,8 +1,95 @@ --- - name: packages + become: yes tags: packages apt: - name: "{{ item }}" + name: "{{ items }}" install_recommends: no - with_items: - - borgbackup + vars: + items: + - borgbackup + +- name: mkdir /etc/borg + become: yes + file: + path: /etc/borg + state: directory + mode: u=rwx,go= + +- name: Generate SSH keys + become: yes + command: ssh-keygen -t ed25519 -N "" -f "{{ ssh_key }}" -C "for borg @ {{ ansible_hostname }}" + args: + creates: "{{ ssh_key }}" + register: ssh_key_generated + +- when: ssh_key_generated.changed + become: yes + fetch: + src: "{{ ssh_key }}.pub" + dest: "files" + +- name: /etc/borg/env + become: yes + copy: + dest: /etc/borg/env + content: | + BORG_REPO="borg@{{ borg_client__server }}:{{ ansible_hostname }}" + BORG_RSH="ssh -i {{ ssh_key}}" + +# " + +- name: /etc/borg/excludes + become: yes + when: borg_client__state == "absent" + file: + path: /etc/borg/excludes + state: absent + +- name: /etc/borg/excludes + when: borg_client__state == "present" + become: yes + copy: + dest: /etc/borg/excludes + content: | + /proc + /dev + /sys + +- name: /etc/borg/patterns + become: yes + copy: + dest: /etc/borg/patterns + content: | + P sh + R / + {% for item in borg_client__patterns %} + {{ item }} + {% endfor %} + +- name: /usr/local/bin/create-backup + become: yes + template: + dest: /usr/local/bin/create-backup + src: bin/create-backup + mode: u=rx,go= + owner: root + group: root + +- become: yes + copy: + dest: /etc/systemd/system/create-backup.service + content: | + [Unit] + Description=Create backup + + [Service] + Type=oneshot + WorkingDirectory=/ + ExecStart=/usr/local/bin/create-backup + register: create_backup_service + +- when: create_backup_service.changed + become: yes + systemd: + daemon_reload: yes |