-
Notifications
You must be signed in to change notification settings - Fork 0
/
snapshot-create.yml
44 lines (38 loc) · 1.46 KB
/
snapshot-create.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
- name: Cleanup snapshot first
ansible.builtin.import_playbook: snapshot-delete.yml
- name: Create new snapshot
hosts: snapshotted
become: true
tasks:
- name: Load timeshift.json
ansible.builtin.slurp:
src: /etc/timeshift/timeshift.json
register: imported_json
- name: Include all user files (so they will be restored)
ansible.builtin.set_fact:
imported_json: "{{ imported_json.content | b64decode | from_json | combine({'exclude': ['+ /home/user/**', '+ /root/**']}) }}"
- name: Write timeshift.json
ansible.builtin.copy:
content: "{{ imported_json | to_nice_json }}"
dest: /etc/timeshift/timeshift.json
owner: root
group: root
mode: "0644"
- name: Create snapshot
ansible.builtin.command:
cmd: "timeshift --scripted --snapshot-device /dev/mapper/{{ inventory_hostname }}--vg-root --create --comment by-ansible --yes"
creates: /timeshift/snapshots/by-ansible
- name: List new snapshots
ansible.builtin.shell:
cmd: ls -td1 *
chdir: /timeshift/snapshots
executable: /bin/bash
changed_when: false
register: new_snapshots
- name: Move snapshot
ansible.builtin.shell:
cmd: mv {{ new_snapshots["stdout_lines"][0].strip() }} by-ansible
chdir: /timeshift/snapshots
creates: /timeshift/snapshots/by-ansible
executable: /bin/bash
when: new_snapshots["stdout_lines"] | length > 0