7from __future__
import absolute_import, division, print_function
10ANSIBLE_METADATA = {
'metadata_version':
'1.1',
11 'status': [
'preview'],
12 'supported_by':
'community'}
17short_description: Manage users
19- Manage users on Cisco ACI Multi-Site.
21- Dag Wieers (@dagwieers)
26 - The name of the user.
32 - The password of the user.
36 - The first name of the user.
37 - This parameter is required when creating new users.
41 - The last name of the user.
42 - This parameter
is required when creating new users.
46 - The email address of the user.
47 - This parameter
is required when creating new users.
51 - The phone number of the user.
52 - This parameter
is required when creating new users.
56 - The status of the user account.
61 - The domain this user belongs to.
62 - When creating new users, this defaults to C(Local).
66 - The roles
for this user.
70 - Use C(present)
or C(absent)
for adding
or removing.
71 - Use C(query)
for listing an object
or multiple objects.
73 choices: [ absent, present, query ]
76- A default installation of ACI Multi-Site ships
with admin password
'we1come!' which requires a password change on first login.
77 See the examples of how to change the
'admin' password using Ansible.
78extends_documentation_fragment: mso
82- name: Update initial admin password
88 user_password: SomeSecretPassword
90 delegate_to: localhost
96 password: SomeSecretPassword
98 description: Test user
101 email: dag@wieers.com
102 phone: +32 478 436 299
104 delegate_to: localhost
110 password: SomeSecretPassword
113 delegate_to: localhost
119 password: SomeSecretPassword
122 delegate_to: localhost
123 register: query_result
125- name: Query all users
129 password: SomeSecretPassword
131 delegate_to: localhost
132 register: query_result
137from ansible.module_utils.basic import AnsibleModule
138from ansible.module_utils.network.aci.mso import MSOModule, mso_argument_spec, issubset
143 argument_spec.update(
144 user=dict(type=
'str', aliases=[
'name']),
145 user_password=dict(type=
'str', no_log=
True),
146 first_name=dict(type=
'str'),
147 last_name=dict(type=
'str'),
148 email=dict(type=
'str'),
149 phone=dict(type=
'str'),
151 account_status=dict(type=
'str', choices=[
'active']),
152 domain=dict(type=
'str'),
153 roles=dict(type=
'list'),
154 state=dict(type=
'str', default=
'present', choices=[
'absent',
'present',
'query']),
158 argument_spec=argument_spec,
159 supports_check_mode=
True,
161 [
'state',
'absent', [
'user']],
162 [
'state',
'present', [
'user']],
166 user_name = module.params[
'user']
167 user_password = module.params[
'user_password']
168 first_name = module.params[
'first_name']
169 last_name = module.params[
'last_name']
170 email = module.params[
'email']
171 phone = module.params[
'phone']
172 account_status = module.params[
'account_status']
173 state = module.params[
'state']
177 roles = mso.lookup_roles(module.params[
'roles'])
178 domain = mso.lookup_domain(module.params[
'domain'])
185 mso.existing = mso.get_obj(path, username=user_name)
187 user_id = mso.existing[
'id']
189 path =
'users/{id}'.
format(id=user_id)
191 mso.existing = mso.query_objs(path)
196 elif state ==
'absent':
197 mso.previous = mso.existing
199 if module.check_mode:
202 mso.existing = mso.request(path, method=
'DELETE')
204 elif state ==
'present':
205 mso.previous = mso.existing
210 password=user_password,
211 firstName=first_name,
215 accountStatus=account_status,
222 mso.sanitize(payload, collate=
True)
224 if mso.sent.get(
'accountStatus')
is None:
225 mso.sent[
'accountStatus'] =
'active'
228 if not issubset(mso.sent, mso.existing):
230 if 'password' in mso.proposed:
231 mso.module.warn(
"A password change is assumed, as the MSO REST API does not return passwords we do not know.")
232 mso.result[
'changed'] =
True
234 if module.check_mode:
235 mso.existing = mso.proposed
237 mso.existing = mso.request(path, method=
'PUT', data=mso.sent)
239 if module.check_mode:
240 mso.existing = mso.proposed
242 mso.existing = mso.request(path, method=
'POST', data=mso.sent)
247if __name__ ==
"__main__":
def issubset(subset, superset)