From d5a5e37fcf39de757ebe66bb239d9b9a5837b9ab Mon Sep 17 00:00:00 2001 From: John Sutterfield Date: Wed, 16 May 2018 14:27:49 -0400 Subject: [PATCH] Add fallback check for IAM role temp creds (#40240) * Add fallback check for IAM role temp creds --- lib/ansible/plugins/inventory/aws_ec2.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/ansible/plugins/inventory/aws_ec2.py b/lib/ansible/plugins/inventory/aws_ec2.py index f379c50f588..20bd19db7f6 100644 --- a/lib/ansible/plugins/inventory/aws_ec2.py +++ b/lib/ansible/plugins/inventory/aws_ec2.py @@ -451,6 +451,13 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable): self.aws_secret_access_key = self._options.get('aws_secret_access_key') self.aws_security_token = self._options.get('aws_security_token') + if not self.boto_profile and not (self.aws_access_key_id and self.aws_secret_access_key): + session = botocore.session.get_session() + if session.get_credentials() is not None: + self.aws_access_key_id = session.get_credentials().access_key + self.aws_secret_access_key = session.get_credentials().secret_key + self.aws_security_token = session.get_credentials().token + 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 " "inventory configuration file or set them as environment variables.")