Closed marcelmamula closed 2 months ago
Issue still persists with latest version:
amazon.aws 8.0.1
Log output
TASK [/mnt/c/scripts/community.sap_infrastructure/roles/sap_vm_provision : AWS IAM Role - HA-Role-Pacemaker] ************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible_collections.amazon.aws.plugins.module_utils.iam.AnsibleIAMError: Failed to create instance profile: An error occurred (EntityAlreadyExists) when calling the CreateInstanceProfile operation: Instance Profile HA-Role-Pacemaker already exists.
in a release after 2026-05-01. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
fatal: [pr2hana0 -> localhost]: FAILED! => {"boto3_version": "1.34.97", "botocore_version": "1.34.97", "changed": false, "error": {"code": "EntityAlreadyExists", "message": "Instance Profile HA-Role-Pacemaker already exists.", "type": "Sender"}, "msg": "Failed to create instance profile: An error occurred (EntityAlreadyExists) when calling the CreateInstanceProfile operation: Instance Profile HA-Role-Pacemaker already exists.", "response_metadata": {"http_headers": {"content-length": "301", "content-type": "text/xml", "date": "Wed, 26 Jun 2024 10:34:26 GMT", "x-amzn-requestid": "X-5e4f-4438-a912-f39dcfb56774"}, "http_status_code": 409, "request_id": "X-5e4f-4438-a912-f39dcfb56774", "retry_attempts": 0}}
What needs to happen to get this issue fixed? It is preventing a lot of us from updating to a newer version.
+1
The original author (wimnat), is no longer involved with the AWS modules, and while I've done a fair bit of work with this module, I've not had as much time to work on things recently (while I work for Red Hat, this collection isn't part of my core responsibilities).
amazon.aws
being the "supported" set of AWS modules, if you are Red Hat customers paying for support of Ansible, then the fastest way to get support will likely be to open a support case through the support portal: https://access.redhat.com/support/
Taking a quick look at the code and combined with some knowledge of the integration tests,
If I had to guess, this issue is triggered when there's a pre-existing instance profile with a different (or no) role attached, would this fit with your environment?
If so, the simplest work around would be to set create_instance_profile: false
and manage the instance profile using the iam_instance_profile
module.
The main issue with the newer versions is that iam_role is no longer idempotent. Maybe I can get some time to poke around on this and understand what has changed to cause this.
Looks to me that some code was dropped during refactor that used to handle this case - https://github.com/ansible-collections/amazon.aws/commit/d3edef2333ceb3aaa826c1ef870accce9848d096#diff-894c5f1bc94d55c144c10f65e632bec917bde2a54d6206a17ac5bb65c1621328
If it's a pure idempotence issue, then our integration tests should be catching it:
This is why I suspect it's related to pre-existing profiles. Another other possibility is that it's getting a permission denied on the ListInstanceProfiles call.
If you're able to create a minimal set of tasks to reproduce the issue (starting from nothing), then your chances of getting a fix are somewhat higher (as the developer doesn't need to figure out where the breakage is first)
As I said though, the work around is simply to split role creation and instance profile creation into two calls:
- amazon.aws.iam_role:
name: "HA-Role-Pacemaker"
create_instance_profile: false
assume_role_policy_document: "{{ assume_policy }}"
- amazon.aws.iam_instance_profile:
name: "HA-Role-Pacemaker"
role: "HA-Role-Pacemaker"
So I decided to experiment a little with 8.1.0 and try to split the call as suggested so amazon.aws.iam_role has create_instance_profile: false and then call amazon.aws.iam_instance_profile. What happened is that I got a message because iam:GetInstanceProfile was not granted. Once I added this permission to the role, I was able to use the single original call.
I don't think the change in https://github.com/braydencw1/amazon.aws/commit/750eef7e222e4a72ecdaf69edd27f6f8772b3a63, which was published in 8.2.0 is correct. When using amazon.aws.iam_role, create_instance_profile: false
DOES NOT work. It still tries to create the profile. Are you sure the change https://github.com/ansible-collections/amazon.aws/blob/8.2.0/plugins/modules/iam_role.py#L733-L734 is correct?
The call was working in 8.1.0
I opened https://github.com/ansible-collections/amazon.aws/issues/2281 to address this problem
Summary
I have been using 7.3.0 collection for some time, but it stopped working with upgrade to 7.5.0. amazon.aws.iam_role is no longer able to ignore already existing entries and it fails with
Issue Type
Bug Report
Component Name
amazon.aws.iam_role
Ansible Version
Collection Versions
AWS SDK versions
Configuration
OS / Environment
SLES for SAP 15 SP3 SLES for SAP 15 SP5 openSUSE Tumbleweed
Steps to Reproduce
https://github.com/sap-linuxlab/community.sap_infrastructure/blob/0e67afc14738c8731192ef9f5040496c4a96e9b1/roles/sap_vm_provision/tasks/platform_ansible/aws_ec2_vs/execute_setup_ha.yml#L257
Expected Results
IAM role HA-Role-Pacemaker is created.
Actual Results
Code of Conduct