Debian Codegraph @

ansible_collections/amazon/aws/tests/integration/targets/iam_user/tasks/main.yml

raw
1 ---
2 - name: Set up aws connection info
3 module_defaults:
4 group/aws:
5 access_key: "{{ aws_access_key }}"
6 secret_key: "{{ aws_secret_key }}"
7 session_token: "{{ security_token | default(omit) }}"
8 region: "{{ aws_region }}"
9 block:
10 - name: Ensure improper usage of parameters fails gracefully
11 amazon.aws.iam_user_info:
12 path: "{{ test_path }}"
13 group: "{{ test_group }}"
14 ignore_errors: true # noqa: ignore-errors
15 register: iam_user_info_path_group
16 - name: Assert friendly error
17 ansible.builtin.assert:
18 that:
19 - iam_user_info_path_group is failed
20 - iam_user_info_path_group.msg.startswith("parameters are mutually exclusive")
21
22 - name: Create test user (check mode)
23 amazon.aws.iam_user:
24 name: "{{ test_user }}"
25 state: present
26 check_mode: true
27 register: iam_user
28 - name: Assert that the user would be created
29 ansible.builtin.assert:
30 that:
31 - iam_user is changed
32
33 - name: Create test user
34 amazon.aws.iam_user:
35 name: "{{ test_user }}"
36 state: present
37 register: iam_user
38 - name: Assert that the user is created
39 ansible.builtin.assert:
40 that:
41 - iam_user is changed
42
43 - name: Ensure test user exists (no change - check mode)
44 amazon.aws.iam_user:
45 name: "{{ test_user }}"
46 state: present
47 register: iam_user
48 check_mode: true
49 - name: Assert that user would not change
50 ansible.builtin.assert:
51 that:
52 - iam_user is not changed
53
54 - name: Ensure test user exists (no change)
55 amazon.aws.iam_user:
56 name: "{{ test_user }}"
57 state: present
58 register: iam_user
59 - name: Assert that the user wasn't changed
60 ansible.builtin.assert:
61 that:
62 - iam_user is not changed
63
64 - name: Ensure the info used to validate other tests is valid
65 ansible.builtin.set_fact:
66 test_iam_user: "{{ iam_user.user }}"
67 - name: Assert expected return values
68 ansible.builtin.assert:
69 that:
70 - test_iam_user.arn.startswith("arn:aws:iam")
71 - test_iam_user.arn.endswith("user/" + test_user )
72 - test_iam_user.create_date is not none
73 - test_iam_user.path == test_path
74 - test_iam_user.user_id is not none
75 - test_iam_user.user_name == test_user
76 - test_iam_user.tags | length == 0
77
78 - name: Get info on IAM user(s)
79 amazon.aws.iam_user_info:
80 register: iam_user_info
81 - name: Assert we got some users returned
82 ansible.builtin.assert:
83 that:
84 - iam_user_info.iam_users | length != 0
85
86 - name: Get info on IAM user(s) with name
87 amazon.aws.iam_user_info:
88 name: "{{ test_user }}"
89 register: iam_user_info
90 - name: Assert we got expected information about user
91 ansible.builtin.assert:
92 that:
93 - iam_user_info.iam_users | length == 1
94 - iam_user_info.iam_users[0].arn == test_iam_user.arn
95 - iam_user_info.iam_users[0].create_date == test_iam_user.create_date
96 - iam_user_info.iam_users[0].path == test_iam_user.path
97 - iam_user_info.iam_users[0].user_id == test_iam_user.user_id
98 - iam_user_info.iam_users[0].user_name == test_iam_user.user_name
99 - iam_user_info.iam_users[0].tags | length == 0
100
101 # ------------------------------------------------------------------------------------------
102
103 - name: Create test user with password (check mode)
104 amazon.aws.iam_user:
105 name: "{{ test_user3 }}"
106 password: "{{ test_password }}"
107 state: present
108 check_mode: true
109 register: iam_user
110 - name: Assert that the second user would be created
111 ansible.builtin.assert:
112 that:
113 - iam_user is changed
114
115 - name: Create second test user with password
116 amazon.aws.iam_user:
117 name: "{{ test_user3 }}"
118 password: "{{ test_password }}"
119 password_reset_required: true
120 state: present
121 wait: false
122 register: iam_user
123 - name: Assert that the second user is created
124 ansible.builtin.assert:
125 that:
126 - iam_user is changed
127 - iam_user.user.password_reset_required
128
129 - name: Get info on IAM user(s) on path
130 amazon.aws.iam_user_info:
131 path: "{{ test_path }}"
132 name: "{{ test_user }}"
133 register: iam_user_info
134 - name: Assert we got expected information about user
135 ansible.builtin.assert:
136 that:
137 - iam_user_info.iam_users | length == 1
138 - iam_user_info.iam_users[0].arn == test_iam_user.arn
139 - iam_user_info.iam_users[0].create_date == test_iam_user.create_date
140 - iam_user_info.iam_users[0].path == test_iam_user.path
141 - iam_user_info.iam_users[0].user_id == test_iam_user.user_id
142 - iam_user_info.iam_users[0].user_name == test_iam_user.user_name
143 - iam_user_info.iam_users[0].tags | length == 0
144
145 # ------------------------------------------------------------------------------------------
146
147 - name: Test path parameter
148 ansible.builtin.include_tasks: path.yml
149 - name: Test boundary parameter
150 ansible.builtin.include_tasks: boundary_policy.yml
151 - name: Test tagging
152 ansible.builtin.include_tasks: tags.yml
153 - name: Test password parameters
154 ansible.builtin.include_tasks: password.yml
155 - name: Test managed_policy parameter
156 ansible.builtin.include_tasks: managed_policies.yml
157 - name: Test iam_user_info
158 ansible.builtin.include_tasks: search_group.yml
159 - name: Test deletion
160 ansible.builtin.include_tasks: deletion.yml
161 always:
162 - name: Remove group
163 amazon.aws.iam_group:
164 name: "{{ test_group }}"
165 state: absent
166 ignore_errors: true # noqa: ignore-errors
167
168 - name: Remove ansible users
169 amazon.aws.iam_user:
170 name: "{{ item }}"
171 state: absent
172 with_items: "{{ test_users }}"
173 ignore_errors: true # noqa: ignore-errors