From a71c207f034d16c46cc063a9f969b57c4b78df67 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Wed, 17 May 2023 12:53:25 +0000 Subject: [PATCH] inventory plugins - Hard code fall-back region to connect to when trying to pull a list of regions (#1552) (#1556) [PR #1552/c9920701 backport][stable-6] inventory plugins - Hard code fall-back region to connect to when trying to pull a list of regions This is a backport of PR #1552 as merged into main (c992070). SUMMARY fixes: #1551 If no regions and no region is provided, then botocore will sometimes refuse to connect to the EC2 endpoint for us to then pull a list of regions... ISSUE TYPE Bugfix Pull Request COMPONENT NAME aws_ec2 inventory plugin ADDITIONAL INFORMATION Nominally botocore should be falling back to a default region, but there are no guarantees Reviewed-by: Mark Chappell --- changelogs/fragments/1551-ec2_inventory-no-region.yml | 2 ++ plugins/plugin_utils/inventory.py | 3 ++- tests/integration/targets/inventory_aws_ec2/aliases | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/1551-ec2_inventory-no-region.yml diff --git a/changelogs/fragments/1551-ec2_inventory-no-region.yml b/changelogs/fragments/1551-ec2_inventory-no-region.yml new file mode 100644 index 00000000000..5b6816e625f --- /dev/null +++ b/changelogs/fragments/1551-ec2_inventory-no-region.yml @@ -0,0 +1,2 @@ +bugfixes: +- aws_ec2 inventory plugin - fix ``NoRegionError`` when no regions are provided and region isn't specified (https://github.com/ansible-collections/amazon.aws/issues/1551). diff --git a/plugins/plugin_utils/inventory.py b/plugins/plugin_utils/inventory.py index 9d17eba2b87..47eb1887e34 100644 --- a/plugins/plugin_utils/inventory.py +++ b/plugins/plugin_utils/inventory.py @@ -117,7 +117,8 @@ def _set_frozen_credentials(self): def _describe_regions(self, service): # Try pulling a list of regions from the service try: - client = self.client(service) + initial_region = self.region or "us-east-1" + client = self.client(service, region=initial_region) resp = client.describe_regions() except AttributeError: # Not all clients support describe diff --git a/tests/integration/targets/inventory_aws_ec2/aliases b/tests/integration/targets/inventory_aws_ec2/aliases index e872d131a87..c96d69a0c60 100644 --- a/tests/integration/targets/inventory_aws_ec2/aliases +++ b/tests/integration/targets/inventory_aws_ec2/aliases @@ -1,3 +1,3 @@ -time=10m +time=15m cloud/aws