| 
					
				 | 
			
			
				@@ -1,55 +1,50 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 - name: install duplicity 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   apt: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    name: duplicity 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    name: '{{duplitab_duplicity_package_name}}' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     state: present 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   become: yes 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-- name: generate commands 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+- name: install duplitab package 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  copy: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    src: '{{duplitab_package_source_path}}' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    dest: '{{duplitab_package_install_path}}' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  become: yes 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  register: duplitab_package 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+- name: install duplitab 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  apt: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    deb: '{{duplitab_package.dest}}' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    state: present 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+- name: generate backup config 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   set_fact: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    backup_command: |- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      {% set source = item.0 %} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      {% set target = item.1 %} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      {% if source.source_host is defined %} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      mount_path="$(mktemp --tmpdir --directory ansible-duplicity-sshfs-XXXXXXXX)"; sshfs "{{source.source_host}}:{{source.source_path}}" $mount_path; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      {%- endif %} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      duplicity --no-print-statistics --verbosity warning 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      {%- if target.encrypt_key is defined %} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-       --encrypt-key "{{target.encrypt_key}}" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      {%- else %} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-       --no-encryption 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      {%- endif %} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      {%- for selector in source.selectors|default([]) %} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      {% if selector['option'] in ['exclude', 'include'] %} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-       --{{selector['option']}} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      {%- if source.source_host is defined %} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-       "{{ selector['shell_pattern'] | replace(source.source_path, '$mount_path') }}" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      {%- else %} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-       "{{selector['shell_pattern']}}" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      {%- endif %} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      {%- endif %} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      {% endfor %} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      {%- if source.source_host is defined %} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-       --allow-source-mismatch "$mount_path" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      {%- else %} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-       "{{source.source_path}}" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      {%- endif %} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-       "{{target.url}}"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      {%- if source.source_host is defined %} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      fusermount -u "$mount_path" && rm -r "$mount_path"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      {%- endif %} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    source_type: "{{item.0.source_host is defined | ternary('sshfs', 'local')}}" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    source_host: "{{item.0.source_host | default(None)}}" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    source_path: "{{item.0.source_path}}" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    selectors: "{{item.0.selectors|default([])}}" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    target_url: "{{item.1.url}}" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    target_via_sshfs: "{{item.1.sshfs | default(False)}}" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    encrypt_key: "{{item.1.encrypt_key | default(None)}}" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    encryption: "{{item.1.encrypt_key is defined}}" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   with_subelements: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  - '{{duplicity_backups}}' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  - '{{duplitab_backups}}' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   - targets 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  register: duplicity_backup_commands 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  register: duplitab_config 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+- name: write /etc/duplitab 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  copy: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    content: "{{duplitab_config.results | map(attribute = 'ansible_facts') | list | to_nice_yaml}}" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    dest: /etc/duplitab 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  become: yes 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 - name: setup cron jobs 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   blockinfile: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     dest: '/etc/crontab' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    marker: '# ANSIBLE DUPLICITY BACKUPS {mark}' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    marker: '# ANSIBLE DUPLITAB BACKUPS {mark}' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     block: |- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      {% for backup in duplicity_backup_commands.results %} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      {% set source = backup.item.0 %} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      {% set target = backup.item.1 %} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      {% for backup_job in target.backup_cron_jobs %} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      {{backup_job.minute}} {{backup_job.hour}} * * * {{source.local_user}} {{backup.ansible_facts.backup_command}} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      {% endfor %} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      {% for job in duplitab_cron_jobs %} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      {{job.minute}} {{job.hour}} * * * {{job.local_user}} duplitab 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      {%- if job.target_url_filter is defined %} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+       --filter-target-url '{{job.target_url_filter}}' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      {%- endif %} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      {%- if job.quiet | default(True) %} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+       --quiet 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      {%- endif %} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+       backup 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       {% endfor %} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   become: yes 
			 |