Skip to content

Commit

Permalink
aws_ec2 inventory - migration to Python 3.6 f-strings (#1526)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tremble authored May 8, 2023
1 parent 183e431 commit 7b4c201
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions changelogs/fragments/fstring-ec2_inv.yml
Original file line number Diff line number Diff line change
@@ -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).
2 changes: 1 addition & 1 deletion plugins/inventory/aws_ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
5 changes: 5 additions & 0 deletions plugins/modules/ec2_vpc_subnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7b4c201

Please sign in to comment.