Fixing race condition in ec2 inventory plugin (#59638)

* Fixing race condition in ec2 inventory plugin

Co-Authored-By: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>

* Fixing code block according to suggestion

* Adding changelog fragment
pull/59659/head
Ihor Borodin 5 years ago committed by Sloane Hertel
parent 007fe842b9
commit 3b5a96fcb7

@ -0,0 +1,2 @@
bugfixes:
- aws_ec2 inventory plugin - fixed race condition when trying to fetch IAM instance profile (role) credentials (https://github.com/ansible/ansible/pull/59638)

@ -579,10 +579,14 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
if not self.boto_profile and not (self.aws_access_key_id and self.aws_secret_access_key): if not self.boto_profile and not (self.aws_access_key_id and self.aws_secret_access_key):
session = botocore.session.get_session() session = botocore.session.get_session()
if session.get_credentials() is not None: try:
self.aws_access_key_id = session.get_credentials().access_key credentials = session.get_credentials().get_frozen_credentials()
self.aws_secret_access_key = session.get_credentials().secret_key except AttributeError:
self.aws_security_token = session.get_credentials().token pass
else:
self.aws_access_key_id = credentials.access_key
self.aws_secret_access_key = credentials.secret_key
self.aws_security_token = credentials.token
if not self.boto_profile and not (self.aws_access_key_id and self.aws_secret_access_key): if not self.boto_profile and not (self.aws_access_key_id and self.aws_secret_access_key):
raise AnsibleError("Insufficient boto credentials found. Please provide them in your " raise AnsibleError("Insufficient boto credentials found. Please provide them in your "

Loading…
Cancel
Save