diff --git a/tasks/main.yml b/tasks/main.yml index 393bcb16018a8151b8758b24f5d74a77adc63f42..60b0d78b12dbeb340db043b400609517af121031 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 ae2d39566dca1ce9b01231ee012a2684fbb62667..76ae5a00e79021cb5de66e07021011e175228e5b 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 c12b35f102f9d9a9db6757f07542db6f628ebb49..f313781d930f715b011bf9c0279f36592f58e8e9 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 }}"