From 671876b26d77f4b3a9036195a4f17432221f197c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20-=20Le=20Filament?= <theo@le-filament.com> Date: Wed, 30 Oct 2024 15:41:45 +0100 Subject: [PATCH] change: better handling of backup accounts --- tasks/main.yml | 13 ++++++++----- templates/backup.yaml.j2 | 4 ++-- templates/restore-odootest.yaml.j2 | 4 ++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index 393bcb1..60b0d78 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -390,6 +390,7 @@ # Allow role vars to work with `item` variable. item: "{{ item_account_instance.1 }}" template_backup_account: "{{ item_account_instance.0 }}" + template_backup_credentials: "{{ swift_odoo_credentials[template_backup_account.key] }}" template_odoo_instance: "{{ odoo_instance }}" template_database_name: "{{ template_odoo_instance.value.db }}" template_odoo_source_instance: "{{ {'key': template_odoo_instance.value.prod_instance | default(template_odoo_instance.key ), 'value': odoo_instances[template_odoo_instance.value.prod_instance | default(template_odoo_instance.key )]} }}" @@ -399,7 +400,7 @@ owner: "root" group: "root" mode: "0400" - loop: "{{ swift_accounts | dict2items | product(odoo_instances | dict2items) }}" + loop: "{{ swift_odoo_accounts | dict2items | product(odoo_instances | dict2items) }}" loop_control: label: "account {{ template_backup_account.key }} on {{ template_odoo_instance.key }}" loop_var: item_account_instance @@ -420,14 +421,16 @@ # Allow role vars to work with `item` variable. item: "{{ item_account_instance.1 }}" template_backup_account: "{{ item_account_instance.0 }}" + template_backup_credentials: "{{ swift_odoo_credentials[template_backup_account.key] }}" template_odoo_instance: "{{ odoo_instance }}" + template_odoo_instance_setup: "{{ odoo_instance_setup }}" ansible.builtin.template: src: "backup.yaml.j2" dest: "/home/docker/backups/backup-{{ template_odoo_instance.key }}{{ template_backup_account.key }}.yaml" owner: "root" group: "root" mode: "0400" - loop: "{{ swift_accounts | dict2items | product(odoo_instances | dict2items) }}" + loop: "{{ swift_odoo_accounts | dict2items | product(odoo_instances | dict2items) }}" loop_control: label: "account {{ template_backup_account.key }} on {{ template_odoo_instance.key }}" loop_var: item_account_instance @@ -447,10 +450,10 @@ template_odoo_instance: "{{ odoo_instance }}" ansible.builtin.cron: name: "backup {{ template_odoo_instance.key }}{{ template_backup_account.key }}" - minute: "{{ '%H' | strftime((('1970-01-01 ' + backup_time_start) | to_datetime).timestamp() + (swift_accounts | length - template_backup_account.key) * ((backup_time_slot_duration | community.general.to_seconds - swift_accounts | length * backup_time_max_duration | community.general.to_seconds) / (swift_accounts | length - 1) + backup_time_max_duration | community.general.to_seconds) | int) }}" - hour: "{{ '%H' | strftime((('1970-01-01 ' + backup_time_start) | to_datetime).timestamp() + (swift_accounts | length - template_backup_account.key) * ((backup_time_slot_duration | community.general.to_seconds - swift_accounts | length * backup_time_max_duration | community.general.to_seconds) / (swift_accounts | length - 1) + backup_time_max_duration | community.general.to_seconds) | int) }}" + minute: "{{ '%H' | strftime((('1970-01-01 ' + backup_time_start) | to_datetime).timestamp() + (swift_odoo_accounts | length - template_backup_account.key) * ((backup_time_slot_duration | community.general.to_seconds - swift_odoo_accounts | length * backup_time_max_duration | community.general.to_seconds) / (swift_odoo_accounts | length - 1) + backup_time_max_duration | community.general.to_seconds) | int) }}" + hour: "{{ '%H' | strftime((('1970-01-01 ' + backup_time_start) | to_datetime).timestamp() + (swift_odoo_accounts | length - template_backup_account.key) * ((backup_time_slot_duration | community.general.to_seconds - swift_odoo_accounts | length * backup_time_max_duration | community.general.to_seconds) / (swift_odoo_accounts | length - 1) + backup_time_max_duration | community.general.to_seconds) | int) }}" job: "/usr/bin/docker compose -f /home/docker/backups/backup-{{ template_odoo_instance.key }}{{ template_backup_account.key }}.yaml run --rm backup_odoo" - loop: "{{ swift_accounts | dict2items | product(odoo_instances | dict2items) }}" + loop: "{{ swift_odoo_accounts | dict2items | product(odoo_instances | dict2items) }}" loop_control: label: "account {{ template_backup_account.key }} on {{ template_odoo_instance.key }}" loop_var: item_account_instance diff --git a/templates/backup.yaml.j2 b/templates/backup.yaml.j2 index ae2d395..76ae5a0 100644 --- a/templates/backup.yaml.j2 +++ b/templates/backup.yaml.j2 @@ -10,8 +10,8 @@ services: PGUSER: "{{ template_odoo_instance.value.db_user }}" PGPASSWORD: "{{ template_odoo_instance.value.db_pass }}" PASSPHRASE: "{{ template_odoo_instance.value.odoo_backup_pass | default(template_odoo_instance.value.master_pass) }}" - SWIFT_USERNAME: "{{ template_backup_account.value.username }}" - SWIFT_PASSWORD: "{{ template_backup_account.value.password }}" + SWIFT_USERNAME: "{{ template_backup_credentials.username }}" + SWIFT_PASSWORD: "{{ template_backup_credentials.password }}" SWIFT_AUTHURL: "{{ template_backup_account.value.authurl }}" SWIFT_AUTHVERSION: {{ template_backup_account.value.authversion }} SWIFT_TENANTNAME: "{{ template_backup_account.value.tenantname }}" diff --git a/templates/restore-odootest.yaml.j2 b/templates/restore-odootest.yaml.j2 index c12b35f..f313781 100644 --- a/templates/restore-odootest.yaml.j2 +++ b/templates/restore-odootest.yaml.j2 @@ -13,8 +13,8 @@ services: - ./pre_restore-{{ template_odoo_instance.key }}.sql:/tmp/pre-restore.sql:ro environment: PGDATABASE: "{{ template_database_name }}" - SWIFT_USERNAME: "{{ template_backup_account.value.username }}" - SWIFT_PASSWORD: "{{ template_backup_account.value.password }}" + SWIFT_USERNAME: "{{ template_backup_credentials.username }}" + SWIFT_PASSWORD: "{{ template_backup_credentials.password }}" SWIFT_AUTHURL: "{{ template_backup_account.value.authurl }}" SWIFT_AUTHVERSION: {{ template_backup_account.value.authversion }} SWIFT_TENANTNAME: "{{ template_backup_account.value.tenantname }}" -- GitLab