From 7b4c2011203f3fc111a73a5a24a1a06dcaf4b5d0 Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Mon, 8 May 2023 10:00:02 +0200 Subject: [PATCH] aws_ec2 inventory - migration to Python 3.6 f-strings (#1526) aws_ec2 inventory - migration to Python 3.6 f-strings SUMMARY We've dropped support for Python <3.6, bulk migrate to fstrings and perform some general string cleanup A combination of black --preview flynt some manual cleanup ISSUE TYPE Feature Pull Request COMPONENT NAME plugins/inventory/aws_ec2.py ADDITIONAL INFORMATION Reviewed-by: Alina Buzachis --- changelogs/fragments/fstring-ec2_inv.yml | 5 +++++ plugins/inventory/aws_ec2.py | 2 +- plugins/modules/ec2_vpc_subnet.py | 5 +++++ tests/integration/targets/inventory_aws_ec2/tasks/setup.yml | 2 +- 4 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/fstring-ec2_inv.yml diff --git a/changelogs/fragments/fstring-ec2_inv.yml b/changelogs/fragments/fstring-ec2_inv.yml new file mode 100644 index 00000000000..130c494209c --- /dev/null +++ b/changelogs/fragments/fstring-ec2_inv.yml @@ -0,0 +1,5 @@ +# 1483 includes a fragment and links to 1513 +trivial: +- bulk migration of ``%`` and ``.format()`` to fstrings (https://github.com/ansible-collections/amazon.aws/pull/1526). +minor_changes: +- ec2_vpc_subnet - retry fetching subnet details after creation if the first attempt fails (https://github.com/ansible-collections/amazon.aws/pull/1526). diff --git a/plugins/inventory/aws_ec2.py b/plugins/inventory/aws_ec2.py index 4295546df41..260ad03d51f 100644 --- a/plugins/inventory/aws_ec2.py +++ b/plugins/inventory/aws_ec2.py @@ -416,7 +416,7 @@ def _prepare_host_vars( if use_contrib_script_compatible_ec2_tag_keys: for k, v in host_vars["tags"].items(): - host_vars["ec2_tag_%s" % k] = v + host_vars[f"ec2_tag_{k}"] = v if hostvars_prefix or hostvars_suffix: for hostvar, hostval in host_vars.copy().items(): diff --git a/plugins/modules/ec2_vpc_subnet.py b/plugins/modules/ec2_vpc_subnet.py index 98aedf4c7c1..c61d9df2bd0 100644 --- a/plugins/modules/ec2_vpc_subnet.py +++ b/plugins/modules/ec2_vpc_subnet.py @@ -481,6 +481,11 @@ def ensure_subnet_present(conn, module): subnet = get_matching_subnet(conn, module, module.params["vpc_id"], module.params["cidr"]) if not module.check_mode and module.params["wait"]: + for _rewait in range(0, 5): + if subnet: + break + time.sleep(2) + subnet = get_matching_subnet(conn, module, module.params["vpc_id"], module.params["cidr"]) # GET calls are not monotonic for map_public_ip_on_launch and assign_ipv6_address_on_creation # so we only wait for those if necessary just before returning the subnet subnet = ensure_final_subnet(conn, module, subnet, start_time) diff --git a/tests/integration/targets/inventory_aws_ec2/tasks/setup.yml b/tests/integration/targets/inventory_aws_ec2/tasks/setup.yml index 36e8a1f8559..47e7f4c88a1 100644 --- a/tests/integration/targets/inventory_aws_ec2/tasks/setup.yml +++ b/tests/integration/targets/inventory_aws_ec2/tasks/setup.yml @@ -7,7 +7,7 @@ owner-id: '125523088429' virtualization-type: hvm root-device-type: ebs - name: 'Fedora-Cloud-Base-34-1.2.x86_64*' + name: 'Fedora-Cloud-Base-37-1.2.x86_64*' register: fedora_images - name: Set image id, vpc cidr and subnet cidr