Skip to content

Commit

Permalink
Add fallback check for IAM role temp creds (ansible#40240)
Browse files Browse the repository at this point in the history
* Add fallback check for IAM role temp creds
  • Loading branch information
jsutter55 authored and s-hertel committed May 16, 2018
1 parent 6227c2a commit d5a5e37
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/ansible/plugins/inventory/aws_ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,13 @@ def _set_credentials(self):
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.")
Expand Down

0 comments on commit d5a5e37

Please sign in to comment.