Skip to content

Commit

Permalink
inventory plugins - Hard code fall-back region to connect to when try…
Browse files Browse the repository at this point in the history
…ing to pull a list of regions (ansible-collections#1552) (ansible-collections#1556)

[PR ansible-collections#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 ansible-collections#1552 as merged into main (c992070).
SUMMARY
fixes: ansible-collections#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
  • Loading branch information
patchback[bot] authored May 17, 2023
1 parent 4e4e1df commit a71c207
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/1551-ec2_inventory-no-region.yml
Original file line number Diff line number Diff line change
@@ -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).
3 changes: 2 additions & 1 deletion plugins/plugin_utils/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/targets/inventory_aws_ec2/aliases
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
time=10m
time=15m

cloud/aws

0 comments on commit a71c207

Please sign in to comment.