7from __future__
import absolute_import, division, print_function
10ANSIBLE_METADATA = {
'metadata_version':
'1.1',
11 'status': [
'preview'],
12 'supported_by':
'community'}
17short_description: Manage tenants
19- Manage tenants on Cisco ACI Multi-Site.
21- Dag Wieers (@dagwieers)
26 - The name of the tenant.
32 - The name of the tenant to be displayed in the web UI.
37 - The description
for this tenant.
41 - A list of associated users
for this tenant.
42 - Using this property will replace any existing associated users.
46 - A list of associated sites
for this tenant.
47 - Using this property will replace any existing associated sites.
51 - Use C(present)
or C(absent)
for adding
or removing.
52 - Use C(query)
for listing an object
or multiple objects.
54 choices: [ absent, present, query ]
56extends_documentation_fragment: mso
60- name: Add a new tenant
64 password: SomeSecretPassword
66 display_name: North European Datacenter
67 description: This tenant manages the NEDC environment.
69 delegate_to: localhost
71- name: Remove a tenant
75 password: SomeSecretPassword
78 delegate_to: localhost
84 password: SomeSecretPassword
87 delegate_to: localhost
88 register: query_result
90- name: Query all tenants
94 password: SomeSecretPassword
96 delegate_to: localhost
97 register: query_result
103from ansible.module_utils.basic import AnsibleModule
104from ansible.module_utils.network.aci.mso import MSOModule, mso_argument_spec, issubset
109 argument_spec.update(
110 description=dict(type=
'str'),
111 display_name=dict(type=
'str'),
112 tenant=dict(type=
'str', aliases=[
'name']),
113 users=dict(type=
'list'),
114 sites=dict(type=
'list'),
115 state=dict(type=
'str', default=
'present', choices=[
'absent',
'present',
'query']),
119 argument_spec=argument_spec,
120 supports_check_mode=
True,
122 [
'state',
'absent', [
'tenant']],
123 [
'state',
'present', [
'tenant']],
127 description = module.params[
'description']
128 display_name = module.params[
'display_name']
129 tenant = module.params[
'tenant']
130 state = module.params[
'state']
135 sites = mso.lookup_sites(module.params[
'sites'])
136 users = mso.lookup_users(module.params[
'users'])
143 mso.existing = mso.get_obj(path, name=tenant)
145 tenant_id = mso.existing[
'id']
147 path =
'tenants/{id}'.
format(id=tenant_id)
149 mso.existing = mso.query_objs(path)
154 elif state ==
'absent':
155 mso.previous = mso.existing
157 if module.check_mode:
160 mso.existing = mso.request(path, method=
'DELETE')
162 elif state ==
'present':
163 mso.previous = mso.existing
166 description=description,
169 displayName=display_name,
170 siteAssociations=sites,
171 userAssociations=users,
174 mso.sanitize(payload, collate=
True)
177 if mso.sent.get(
'displayName')
is None:
178 mso.sent[
'displayName'] = tenant
181 if mso.sent.get(
'userAssociations')
is None:
182 mso.sent[
'userAssociations'] = [dict(userId=
"0000ffff0000000000000020")]
185 if not issubset(mso.sent, mso.existing):
186 if module.check_mode:
187 mso.existing = mso.proposed
189 mso.existing = mso.request(path, method=
'PUT', data=mso.sent)
191 if module.check_mode:
192 mso.existing = mso.proposed
194 mso.existing = mso.request(path, method=
'POST', data=mso.sent)
199if __name__ ==
"__main__":
def issubset(subset, superset)