From 67a9e4af26064832cd7883ca4fc7bd58adbf70d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillaume=20Cor=C3=A9?= Date: Thu, 2 Nov 2023 15:57:37 +0100 Subject: [PATCH] Allow passing reservation when creating accounts --- playbooks/readme.adoc | 46 +++++++++++++++++++ .../roles/infra-aws-sandbox/tasks/pool.yml | 12 ++++- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/playbooks/readme.adoc b/playbooks/readme.adoc index ceac4003..fff26199 100644 --- a/playbooks/readme.adoc +++ b/playbooks/readme.adoc @@ -19,3 +19,49 @@ sandbox-list --sort name -all |awk '/^sandbox3001 /{flag=1}flag{print $1 " " $3} # Go back on admin host, ensure they are all valide ./validate.yml -e account_num_start=3001 -e account_num_end=3010 ---- + +=== Create new sandboxes for a specific reservation and OU === + +WARNING: This should be done only when strictly necessary. Prefer the regular process of creating/scaling a reservation using existing sandboxes from the available pool instead, see link:../tools/readme.adoc[tools/readme.adoc] + +. First, Make sure the reservation already exists in the DB, see link:../tools/readme.adoc[tools/readme.adoc] ++ +---- +[opentlc-mgr@admin (PROD) ~]$ . ~/pool_management/python_virtualenv/bin/activate +(python_virtualenv) [opentlc-mgr@admin (PROD) ~]$ cd pool_management/sandbox/playbooks + +START=3200 +COUNT=10 +END=3210 +RESERVATION=rosa-test + +# .create 10 AWS sandbox accounts: sandbox$START .. sandbox$END +./create_range.yml -e account_num_start=$START -e account_count=$COUNT -e sandbox_reservation=$RESERVATION -e account_destination_ou=rosa + +# Add GOLD IMAGES to the new accounts +# Generate the list of new sandboxes + +sandbox-list --sort name -all |awk '/^sandbox'$START' /{flag=1}flag{print $1 " " $3}' > new_sandboxes.txt + +# SSH to QA or a place where node is installed, copy new_sandboxes.txt there +# Run cloud-automation to subscribe to GOLD images, see cloud-automation readme + +# Go back on admin host, ensure they are all valide +./validate.yml -e account_num_start=$START -e account_num_end=$END + +# If all goes well, enable the sandboxes +for i in $(seq $START $END); do + sandbox_enable.sh sandbox$i +done + +# check the new number of sandboxes in the reservation +sandbox-list --all --reservation $RESERVATION +sandbox-list --all --no-headers --reservation $RESERVATION | wc -l +---- +. Manually update the count in the `reservations` to match the number of sandboxes in the reservation. ++ +.Increase the count to match the actual number, replace `CHANGE_ME` +[source,sql] +---- +update reservation set request = jsonb_set(request, '{resources, 0, count}',to_jsonb(CHANGE_ME)) where reservation_name='rosa-test'; +---- diff --git a/playbooks/roles/infra-aws-sandbox/tasks/pool.yml b/playbooks/roles/infra-aws-sandbox/tasks/pool.yml index 23b124b7..3b9a8217 100644 --- a/playbooks/roles/infra-aws-sandbox/tasks/pool.yml +++ b/playbooks/roles/infra-aws-sandbox/tasks/pool.yml @@ -14,6 +14,16 @@ - debug: var: _getaccount +- when: sandbox_reservation | default("", true) not in ["", "None", "null"] + set_fact: + additional_data: + reservation: + S: "{{ sandbox_reservation }}" + +- when: sandbox_reservation | default("", true) in ["", "None", "null"] + set_fact: + additional_data: {} + - name: Create account in DB if it doesn't exist vars: _data: @@ -35,7 +45,7 @@ aws --profile {{ dynamodb_profile }} --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: _putaccount when: _getaccount.stdout == '' or force_create