forked from ansible/ansible
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve iam_group exception handling (ansible#45599)
* Improve iam_group exception handling Use AnsibleAWSModule for iam_group and handle BotoCoreErrors as well as ClientErrors. Use fail_json_aws to improve error messages * Add minimal iam_group test suite Update some of the read-only IAM permissions (this is not sufficient to run the test suite but it gets further than it did until it tries to add a (non-existent) user) * Clean up after tests
- Loading branch information
1 parent
5c49641
commit d2569a3
Showing
4 changed files
with
115 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
unsupported | ||
cloud/aws |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
- name: set up aws connection info | ||
set_fact: | ||
aws_connection_info: &aws_connection_info | ||
aws_access_key: "{{ aws_access_key }}" | ||
aws_secret_key: "{{ aws_secret_key }}" | ||
security_token: "{{ security_token }}" | ||
region: "{{ aws_region }}" | ||
no_log: yes | ||
|
||
- name: ensure ansible user exists | ||
iam_user: | ||
name: AnsibleTestUser | ||
state: present | ||
<<: *aws_connection_info | ||
|
||
- name: ensure group exists | ||
iam_group: | ||
name: ansible_test | ||
users: | ||
- AnsibleTestUser | ||
state: present | ||
<<: *aws_connection_info | ||
register: iam_group | ||
|
||
- assert: | ||
that: | ||
- iam_group.users | ||
|
||
- name: add non existent user to group | ||
iam_group: | ||
name: ansible_test | ||
users: | ||
- AnsibleTestUser | ||
- NonExistentUser | ||
state: present | ||
<<: *aws_connection_info | ||
ignore_errors: yes | ||
register: iam_group | ||
|
||
- name: assert that adding non existent user to group fails with helpful message | ||
assert: | ||
that: | ||
- iam_group is failed | ||
- iam_group.msg.startswith("Couldn't add user NonExistentUser to group ansible_test") | ||
|
||
- name: remove a user | ||
iam_group: | ||
name: ansible_test | ||
purge_users: True | ||
users: [] | ||
state: present | ||
<<: *aws_connection_info | ||
register: iam_group | ||
|
||
- assert: | ||
that: | ||
- iam_group.changed | ||
- not iam_group.users | ||
|
||
- name: remove group | ||
iam_group: | ||
name: ansible_test | ||
state: absent | ||
<<: *aws_connection_info | ||
|
||
- name: remove ansible user | ||
iam_user: | ||
name: AnsibleTestUser | ||
state: absent | ||
<<: *aws_connection_info |