Compare commits
	
		
			1 Commits
		
	
	
		
			cc8e06f7d5
			...
			a3f740d74e
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						
						
							
						
						a3f740d74e
	
				 | 
					
					
						
@@ -8,6 +8,7 @@ restic_user_system: false
 | 
				
			|||||||
restic_state: present
 | 
					restic_state: present
 | 
				
			||||||
restic_version: "0.17.3"
 | 
					restic_version: "0.17.3"
 | 
				
			||||||
restic_job_name: default
 | 
					restic_job_name: default
 | 
				
			||||||
 | 
					restic_job_state: "{{ restic_state }}"
 | 
				
			||||||
restic_job_directory: "/etc/restic"
 | 
					restic_job_directory: "/etc/restic"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
restic_package_name: restic
 | 
					restic_package_name: restic
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										31
									
								
								roles/restic/tasks/configure.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								roles/restic/tasks/configure.yml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,31 @@
 | 
				
			|||||||
 | 
					---
 | 
				
			||||||
 | 
					- name: Ensure systemd timer file for '{{ restic_job_name }}' is {{ restic_state }}'
 | 
				
			||||||
 | 
					  template:
 | 
				
			||||||
 | 
					    dest: "/etc/systemd/system/{{ restic_systemd_unit_naming_scheme }}.timer"
 | 
				
			||||||
 | 
					    src: restic.timer.j2
 | 
				
			||||||
 | 
					    owner: root
 | 
				
			||||||
 | 
					    group: root
 | 
				
			||||||
 | 
					    mode: "0640"
 | 
				
			||||||
 | 
					  when: restic_state == 'present'
 | 
				
			||||||
 | 
					  notify:
 | 
				
			||||||
 | 
					    - reload-systemd
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- name: Ensure restic configuration for '{{ restic_job_name }}' is {{ restic_job_state }}
 | 
				
			||||||
 | 
					  ansible.builtin.template:
 | 
				
			||||||
 | 
					    src: "restic.conf.j2"
 | 
				
			||||||
 | 
					    dest: "{{ restic_job_directory }}/{{ restic_job_name }}.conf"
 | 
				
			||||||
 | 
					    mode: "0640"
 | 
				
			||||||
 | 
					  when: restic_job_state in ['present', 'masked']
 | 
				
			||||||
 | 
					  notify:
 | 
				
			||||||
 | 
					    - trigger-restic
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- name: Ensure restic configuration for '{{ restic_job_name }}' is {{ restic_job_state }}
 | 
				
			||||||
 | 
					  ansible.builtin.file:
 | 
				
			||||||
 | 
					    path: "{{ restic_job_directory }}/{{ restic_job_name }}.conf"
 | 
				
			||||||
 | 
					    state: "{{ restic_job_state }}"
 | 
				
			||||||
 | 
					  when: restic_job_state not in ['present', 'masked']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- name: Flush handlers to ensure systemd knows about '{{ restic_job_name }}'
 | 
				
			||||||
 | 
					  meta: flush_handlers
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -17,4 +17,32 @@
 | 
				
			|||||||
        state: present
 | 
					        state: present
 | 
				
			||||||
      when: ansible_os_family not in ['RedHat', 'Debian']
 | 
					      when: ansible_os_family not in ['RedHat', 'Debian']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- name: Ensure restic backup scripts are {{ restic_state }}
 | 
				
			||||||
 | 
					  ansible.builtin.copy:
 | 
				
			||||||
 | 
					    src: "{{ script.source }}"
 | 
				
			||||||
 | 
					    dest: "{{ script.destination }}"
 | 
				
			||||||
 | 
					    mode: "{{ script.mode }}"
 | 
				
			||||||
 | 
					  loop:
 | 
				
			||||||
 | 
					    - source: restic-backup.sh
 | 
				
			||||||
 | 
					      destination: "{{ restic_systemd_service_exec_start }}"
 | 
				
			||||||
 | 
					      mode: "0510"
 | 
				
			||||||
 | 
					    - source: restic-snapshot-metrics.sh
 | 
				
			||||||
 | 
					      destination: "{{ restic_script_generate_snapshot_metrics }}"
 | 
				
			||||||
 | 
					      mode: "0510"
 | 
				
			||||||
 | 
					  loop_control:
 | 
				
			||||||
 | 
					    loop_var: script
 | 
				
			||||||
 | 
					    label: "{{ script.source }}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- name: Ensure systemd service file for restic template unit is {{ restic_state }}
 | 
				
			||||||
 | 
					  ansible.builtin.template:
 | 
				
			||||||
 | 
					    dest: "/etc/systemd/system/restic@.service"
 | 
				
			||||||
 | 
					    src: "restic@.service.j2"
 | 
				
			||||||
 | 
					    owner: root
 | 
				
			||||||
 | 
					    group: root
 | 
				
			||||||
 | 
					    mode: "0640"
 | 
				
			||||||
 | 
					  when: restic_state == 'present'
 | 
				
			||||||
 | 
					  notify:
 | 
				
			||||||
 | 
					    - reload-systemd
 | 
				
			||||||
 | 
					    - trigger-restic
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,52 +15,16 @@
 | 
				
			|||||||
    create_home: "{{ restic_user_create_home }}"
 | 
					    create_home: "{{ restic_user_create_home }}"
 | 
				
			||||||
  when: restic_create_user
 | 
					  when: restic_create_user
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- name: Ensure restic backup scripts are {{ restic_state }}
 | 
					- name: Ensure restic configuration for job is {{ restic_job_state }}
 | 
				
			||||||
  ansible.builtin.copy:
 | 
					  ansible.builtin.include_tasks:
 | 
				
			||||||
    src: "{{ script.source }}"
 | 
					    file: "configure.yml"
 | 
				
			||||||
    dest: "{{ script.destination }}"
 | 
					 | 
				
			||||||
    mode: "{{ script.mode }}"
 | 
					 | 
				
			||||||
  loop:
 | 
					 | 
				
			||||||
    - source: restic-backup.sh
 | 
					 | 
				
			||||||
      destination: "{{ restic_systemd_service_exec_start }}"
 | 
					 | 
				
			||||||
      mode: "0510"
 | 
					 | 
				
			||||||
    - source: restic-snapshot-metrics.sh
 | 
					 | 
				
			||||||
      destination: "{{ restic_script_generate_snapshot_metrics }}"
 | 
					 | 
				
			||||||
      mode: "0510"
 | 
					 | 
				
			||||||
  loop_control:
 | 
					 | 
				
			||||||
    loop_var: script
 | 
					 | 
				
			||||||
    label: "{{ script.source }}"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
- name: Ensure systemd service file for '{{ restic_job_name }}' is templated
 | 
					 | 
				
			||||||
  template:
 | 
					 | 
				
			||||||
    dest: "/etc/systemd/system/{{ restic_systemd_unit_naming_scheme }}.service"
 | 
					 | 
				
			||||||
    src: restic.service.j2
 | 
					 | 
				
			||||||
    owner: root
 | 
					 | 
				
			||||||
    group: root
 | 
					 | 
				
			||||||
    mode: 0640
 | 
					 | 
				
			||||||
  notify:
 | 
					 | 
				
			||||||
    - reload-systemd
 | 
					 | 
				
			||||||
    - trigger-restic
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
- name: Ensure systemd service file for '{{ restic_job_name }}' is templated
 | 
					 | 
				
			||||||
  template:
 | 
					 | 
				
			||||||
    dest: "/etc/systemd/system/{{ restic_systemd_unit_naming_scheme }}.timer"
 | 
					 | 
				
			||||||
    src: restic.timer.j2
 | 
					 | 
				
			||||||
    owner: root
 | 
					 | 
				
			||||||
    group: root
 | 
					 | 
				
			||||||
    mode: 0640
 | 
					 | 
				
			||||||
  notify:
 | 
					 | 
				
			||||||
    - reload-systemd
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
- name: Flush handlers to ensure systemd knows about '{{ restic_job_name }}'
 | 
					 | 
				
			||||||
  meta: flush_handlers
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
- name: Ensure systemd timer for '{{ restic_job_name }}' is activated
 | 
					- name: Ensure systemd timer for '{{ restic_job_name }}' is activated
 | 
				
			||||||
  systemd:
 | 
					  ansible.builtin.systemd:
 | 
				
			||||||
    name: "{{ restic_systemd_unit_naming_scheme }}.timer"
 | 
					    name: "{{ restic_systemd_unit_naming_scheme }}.timer"
 | 
				
			||||||
    enabled: true
 | 
					    enabled: true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- name: Ensure systemd timer for '{{ restic_job_name }}' is started
 | 
					- name: Ensure systemd timer for '{{ restic_job_name }}' is {{ restic_job_state }}
 | 
				
			||||||
  systemd:
 | 
					  ansible.builtin.systemd:
 | 
				
			||||||
    name: "{{ restic_systemd_unit_naming_scheme }}.timer"
 | 
					    name: "{{ restic_systemd_unit_naming_scheme }}.timer"
 | 
				
			||||||
    state: started
 | 
					    state: started # TODO: mask a timer?
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,3 +2,8 @@
 | 
				
			|||||||
restic_states:
 | 
					restic_states:
 | 
				
			||||||
  - "present"
 | 
					  - "present"
 | 
				
			||||||
  - "absent"
 | 
					  - "absent"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					restic_job_states:
 | 
				
			||||||
 | 
					  - "present"
 | 
				
			||||||
 | 
					  - "masked"
 | 
				
			||||||
 | 
					  - "absent"
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user