Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[aws] Revert back to getting the AWS role name from the URI #49427

Merged
merged 2 commits into from
Dec 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/49113-iam-role-arn-parsing-updated.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- ec2_metadata_facts - Parse IAM role name from the security credential field since the instance profile name is different
7 changes: 4 additions & 3 deletions lib/ansible/modules/cloud/amazon/ec2_metadata_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,9 @@ def _mangle_fields(self, fields, uri, filter_patterns=None):
new_fields = {}
for key, value in fields.items():
split_fields = key[len(uri):].split('/')
if len(split_fields) == 2 and split_fields[0:2] == ['iam', 'info_instanceprofilearn']:
new_fields[self._prefix % "iam-instance-profile-role"] = value.split('/')[1]
# Parse out the IAM role name (which is _not_ the same as the instance profile name)
if len(split_fields) == 3 and split_fields[0:2] == ['iam', 'security-credentials'] and ':' not in split_fields[2]:
new_fields[self._prefix % "iam-instance-profile-role"] = split_fields[2]
if len(split_fields) > 1 and split_fields[1]:
new_key = "-".join(split_fields)
new_fields[self._prefix % new_key] = value
Expand Down Expand Up @@ -504,7 +505,7 @@ def fetch(self, uri, recurse=True):
dict = json.loads(content)
self._data['%s' % (new_uri)] = content
for (key, value) in dict.items():
self._data['%s_%s' % (new_uri, key.lower())] = value
self._data['%s:%s' % (new_uri, key.lower())] = value
except:
self._data['%s' % (new_uri)] = content # not a stringifed JSON string

Expand Down