From 08fb2e5696e6fe2c00710bcd276b6fe461684e33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillaume=20Cor=C3=A9?= Date: Thu, 28 Sep 2023 16:48:29 +0200 Subject: [PATCH] Path reset playbook to keep reservation name. --- .../roles/infra-aws-sandbox/tasks/pool.yml | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/playbooks/roles/infra-aws-sandbox/tasks/pool.yml b/playbooks/roles/infra-aws-sandbox/tasks/pool.yml index f1800c29..3a12ca7e 100644 --- a/playbooks/roles/infra-aws-sandbox/tasks/pool.yml +++ b/playbooks/roles/infra-aws-sandbox/tasks/pool.yml @@ -44,6 +44,36 @@ - when: operation == 'RESET' block: + - name: Get sandbox reservation + vars: + _data: + name: + S: "{{ account_name }}" + command: >- + aws --profile {{ dynamodb_profile | quote }} + --region {{ dynamodb_region | quote }} + dynamodb get-item + --table-name {{ dynamodb_table }} + --key '{{ _data | to_json }}' + --query 'Item.reservation' + --output text + register: r_get_reservation + changed_when: false + + - name: Save some values for after cleanup + set_fact: + sandbox_reservation: "{{ r_get_reservation.stdout }}" + + - when: sandbox_reservation | default("") != "" + set_fact: + additional_data: + reservation: + S: "{{ sandbox_reservation }}" + + - when: sandbox_reservation | default("") == "" + set_fact: + additional_data: {} + - name: Pre-Reset account information for validation vars: _data: @@ -66,7 +96,7 @@ --region {{ dynamodb_region }} dynamodb put-item --table-name {{ dynamodb_table }} - --item '{{ _data | to_json }}' + --item '{{ _data | combine(additional_data | default({}), recursive=True) | to_json }}' - name: Validate Sandbox include_tasks: validate.yaml @@ -93,5 +123,5 @@ --region {{ dynamodb_region }} dynamodb put-item --table-name {{ dynamodb_table }} - --item '{{ _data | to_json }}' + --item '{{ _data | combine(additional_data | default({}), recursive=True) | to_json }}' register: _resetaccount