Răsfoiți Sursa

multiple targets per source possible

Fabian Peter Hammerle 8 ani în urmă
părinte
comite
a287056dd0
1 a modificat fișierele cu 18 adăugiri și 12 ștergeri
  1. 18 12
      tasks/main.yml

+ 18 - 12
tasks/main.yml

@@ -6,30 +6,34 @@
 - name: generate commands
   set_fact:
     backup_command: |-
-      {% if item.source_host is defined %}
-      mount_path="$(mktemp --tmpdir --directory ansible-duplicity-sshfs-XXXXXXXX)"; sshfs "{{item.source_host}}:{{item.source_path}}" $mount_path;
+      {% 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-encryption --no-print-statistics --verbosity warning
-      {%- for selector in item.selectors|default([]) %}
+      {%- for selector in source.selectors|default([]) %}
       {% if selector['option'] in ['exclude', 'include'] %}
        --{{selector['option']}}
-      {%- if item.source_host is defined %}
-       "{{ selector['shell_pattern'] | replace(item.source_path, '$mount_path') }}"
+      {%- if source.source_host is defined %}
+       "{{ selector['shell_pattern'] | replace(source.source_path, '$mount_path') }}"
       {%- else %}
        "{{selector['shell_pattern']}}"
       {%- endif %}
       {%- endif %}
       {% endfor %}
-      {%- if item.source_host is defined %}
+      {%- if source.source_host is defined %}
        --allow-source-mismatch "$mount_path"
       {%- else %}
-       "{{item.source_path}}"
+       "{{source.source_path}}"
       {%- endif %}
-       "{{item.target_url}}";
-      {%- if item.source_host is defined %}
+       "{{target.url}}";
+      {%- if source.source_host is defined %}
       fusermount -u "$mount_path" && rm -r "$mount_path";
       {%- endif %}
-  with_items: '{{duplicity_backups}}'
+  with_subelements:
+  - '{{duplicity_backups}}'
+  - targets
   register: duplicity_backup_commands
 - name: setup cron jobs
   blockinfile:
@@ -37,8 +41,10 @@
     marker: '# ANSIBLE DUPLICITY BACKUPS {mark}'
     block: |-
       {% for backup in duplicity_backup_commands.results %}
-      {% for backup_job in backup.item.backup_cron_jobs %}
-      {{backup_job.minute}} {{backup_job.hour}} * * * {{backup.item.local_user}} {{backup.ansible_facts.backup_command}}
+      {% 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 %}
       {% endfor %}
   become: yes