From d46ed88fa398a553d3eb5b3e6b4f3a2c069958c8 Mon Sep 17 00:00:00 2001 From: Ryan Brown Date: Thu, 11 Oct 2018 12:43:14 -0400 Subject: [PATCH] [aws] Fix IAM role name parsing to come from the ARN (#46076) * [aws] Change IAM role name parsing to come from the ARN (#45534) (cherry picked from commit fe6b7f6b5d1aff0e86802c4bbe4c5c4410ed9ee9) * Changelog --- changelogs/fragments/54434-iam-role-arn-parsing.yml | 2 ++ lib/ansible/modules/cloud/amazon/ec2_metadata_facts.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/54434-iam-role-arn-parsing.yml diff --git a/changelogs/fragments/54434-iam-role-arn-parsing.yml b/changelogs/fragments/54434-iam-role-arn-parsing.yml new file mode 100644 index 00000000000..5a950c3daab --- /dev/null +++ b/changelogs/fragments/54434-iam-role-arn-parsing.yml @@ -0,0 +1,2 @@ +bugfixes: + - ec2_metadata_facts - Parse IAM role name from metadata ARN instead of security credential field. diff --git a/lib/ansible/modules/cloud/amazon/ec2_metadata_facts.py b/lib/ansible/modules/cloud/amazon/ec2_metadata_facts.py index 5a0f542f3a0..2416f9f31c8 100644 --- a/lib/ansible/modules/cloud/amazon/ec2_metadata_facts.py +++ b/lib/ansible/modules/cloud/amazon/ec2_metadata_facts.py @@ -467,8 +467,8 @@ class Ec2Metadata(object): new_fields = {} for key, value in fields.items(): split_fields = key[len(uri):].split('/') - if len(split_fields) == 3 and split_fields[0:2] == ['iam', 'security-credentials']: - new_fields[self._prefix % "iam-instance-profile-role"] = split_fields[2] + if len(split_fields) == 2 and split_fields[0:2] == ['iam', 'info_instanceprofilearn']: + new_fields[self._prefix % "iam-instance-profile-role"] = value.split('/')[1] if len(split_fields) > 1 and split_fields[1]: new_key = "-".join(split_fields) new_fields[self._prefix % new_key] = value