Debian Codegraph @

ansible_collections/amazon/aws/tests/integration/targets/iam_group/tasks/users.yml

raw
1 ---
2 - name: Add non existent user to group
3 amazon.aws.iam_group:
4 name: "{{ test_group }}"
5 users:
6 - "{{ test_user }}"
7 - NonExistentUser
8 state: present
9 ignore_errors: true
10 register: iam_group
11
12 - name: Assert that adding non existent user to group fails with helpful message
13 ansible.builtin.assert:
14 that:
15 - iam_group is failed
16 - iam_group.msg.startswith("Failed to add user NonExistentUser to group")
17
18 - name: Remove a user
19 amazon.aws.iam_group:
20 name: "{{ test_group }}"
21 purge_users: true
22 users: []
23 state: present
24 register: iam_group
25
26 - ansible.builtin.assert:
27 that:
28 - iam_group is changed
29 - '"users" in iam_group.iam_group'
30 - iam_group.iam_group.users | length == 0
31
32 - name: Re-remove a user (no change)
33 amazon.aws.iam_group:
34 name: "{{ test_group }}"
35 purge_users: true
36 users: []
37 state: present
38 register: iam_group
39
40 - ansible.builtin.assert:
41 that:
42 - iam_group is not changed
43 - '"users" in iam_group.iam_group'
44 - iam_group.iam_group.users | length == 0
45
46 - name: Add the user again
47 amazon.aws.iam_group:
48 name: "{{ test_group }}"
49 users:
50 - "{{ test_user }}"
51 state: present
52 register: iam_group
53
54 - ansible.builtin.assert:
55 that:
56 - iam_group is changed
57 - '"users" in iam_group.iam_group'
58 - iam_group.iam_group.users | length == 1
59 - iam_group.iam_group.users[0].user_name == test_user
60
61 - name: Re-add the user
62 amazon.aws.iam_group:
63 name: "{{ test_group }}"
64 users:
65 - "{{ test_user }}"
66 state: present
67 register: iam_group
68
69 - ansible.builtin.assert:
70 that:
71 - iam_group is not changed
72 - '"users" in iam_group.iam_group'
73 - iam_group.iam_group.users | length == 1
74 - iam_group.iam_group.users[0].user_name == test_user