ansible_role_restic/tasks/configure.yml
2024-12-16 15:08:49 +01:00

30 lines
1.6 KiB
YAML

---
- name: (CONF)Initialize repository
ansible.builtin.command: "{{ restic_install_path }}/restic init"
environment:
RESTIC_REPOSITORY: "{{ item.value.location }}"
RESTIC_PASSWORD: "{{ item.value.password }}"
AWS_ACCESS_KEY_ID: '{{ item.value.aws_access_key | default("") }}'
AWS_SECRET_ACCESS_KEY: '{{ item.value.aws_secret_access_key | default("") }}'
AWS_DEFAULT_REGION: '{{ item.value.aws_default_region | default("") }}'
AZURE_ACCOUNT_NAME: '{{ item.value.azure_account_name | default("") }}'
AZURE_ACCOUNT_KEY: '{{ item.value.azure_account_key | default("") }}'
AZURE_ACCOUNT_SAS: '{{ item.value.azure_account_sas | default("") }}'
AZURE_ENDPOINT_SUFFIX: '{{ item.value.azure_endpoint_suffix | default("") }}'
B2_ACCOUNT_ID: '{{ item.value.b2_account_id | default("") }}'
B2_ACCOUNT_KEY: '{{ item.value.b2_account_key | default("") }}'
GOOGLE_PROJECT_ID: '{{ item.value.google_project_id | default("") }}'
GOOGLE_APPLICATION_CREDENTIALS: '{{ item.value.google_application_credentials | default("") }}'
GOOGLE_ACCESS_TOKEN: '{{ item.value.google_access_token | default("") }}'
no_log: "{{ restic_no_log }}"
register: restic_init
changed_when: "'created restic repository' in restic_init.stdout"
failed_when:
- restic_init.rc != 0
- not 'config file already exists' in restic_init.stderr
- not 'config already initialized' in restic_init.stderr
- not 'config already exists' in restic_init.stderr
loop: "{{ restic_repos | dict2items }}"
when:
- item.value.init is defined
- item.value.init|bool