Rename MSC modules to MSO nomenclature (#50959)

* msc_tenant: improve docs

* Rename MSC modules to MSO

* Rename MSC-related objects to MSO nomenclature

* Add missing doc fragments
pull/50981/head
Dag Wieers 5 years ago committed by GitHub
parent 7a1ceb6988
commit a79441ca30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1169,12 +1169,14 @@ files:
- jinja2
lib/ansible/utils/module_docs_fragments/:
support: community
lib/ansible/utils/module_docs_fragments/aci.py: *aci
lib/ansible/utils/module_docs_fragments/acme.py:
maintainers: resmo felixfontein
lib/ansible/utils/module_docs_fragments/docker.py:
support: community
maintainers: $team_docker
supershipit: felixfontein
lib/ansible/utils/module_docs_fragments/mso.py: *aci
lib/ansible/utils/module_docs_fragments/xenserver.py:
maintainers: bvitnik
lib/ansible/utils/module_docs_fragments/cloudstack.py:
@ -1230,7 +1232,7 @@ files:
maintainers: $team_google
supershipit: $team_google
test/integration/targets/meraki: *meraki
test/integration/targets/msc: *aci
test/integration/targets/mso: *aci
test/integration/targets/nxos:
maintainers: $team_nxos
labels:

@ -73,7 +73,7 @@ def update_qs(params):
return '?' + urlencode(accepted_params)
def msc_argument_spec():
def mso_argument_spec():
return dict(
host=dict(type='str', required=True, aliases=['hostname']),
port=dict(type='int', required=False),
@ -87,7 +87,7 @@ def msc_argument_spec():
)
class MSCModule(object):
class MSOModule(object):
def __init__(self, module):
self.module = module
@ -131,7 +131,7 @@ class MSCModule(object):
self.module.fail_json(msg="Parameter 'password' is required for authentication")
def login(self):
''' Log in to MSC '''
''' Log in to MSO '''
# Perform login request
self.url = urljoin(self.baseuri, 'auth/login')
@ -144,7 +144,7 @@ class MSCModule(object):
timeout=self.params['timeout'],
use_proxy=self.params['use_proxy'])
# Handle MSC response
# Handle MSO response
if auth['status'] != 201:
self.response = auth['msg']
self.status = auth['status']
@ -155,7 +155,7 @@ class MSCModule(object):
self.headers['Authorization'] = 'Bearer {token}'.format(**payload)
def request(self, path, method=None, data=None, qs=None):
''' Generic HTTP method for MSC requests. '''
''' Generic HTTP method for MSO requests. '''
self.path = path
if method is not None:
@ -198,14 +198,14 @@ class MSCModule(object):
except Exception:
payload = json.loads(info['body'])
if 'code' in payload:
self.fail_json(msg='MSC Error {code}: {message}'.format(**payload), data=data, info=info, payload=payload)
self.fail_json(msg='MSO Error {code}: {message}'.format(**payload), data=data, info=info, payload=payload)
else:
self.fail_json(msg='MSC Error:'.format(**payload), data=data, info=info, payload=payload)
self.fail_json(msg='MSO Error:'.format(**payload), data=data, info=info, payload=payload)
return {}
def query_objs(self, path, key=None, **kwargs):
''' Query the MSC REST API for objects in a path '''
''' Query the MSO REST API for objects in a path '''
found = []
objs = self.request(path, method='GET')
@ -223,7 +223,7 @@ class MSCModule(object):
return found
def get_obj(self, path, **kwargs):
''' Get a specific object from a set of MSC REST objects '''
''' Get a specific object from a set of MSO REST objects '''
objs = self.query_objs(path, **kwargs)
if len(objs) == 0:
return {}

@ -13,7 +13,7 @@ ANSIBLE_METADATA = {'metadata_version': '1.1',
DOCUMENTATION = r'''
---
module: msc_label
module: mso_label
short_description: Manage labels
description:
- Manage labels on Cisco ACI Multi-Site.
@ -45,13 +45,13 @@ options:
type: str
choices: [ absent, present, query ]
default: present
extends_documentation_fragment: msc
extends_documentation_fragment: mso
'''
EXAMPLES = r'''
- name: Add a new label
msc_label:
host: msc_host
mso_label:
host: mso_host
username: admin
password: SomeSecretPassword
label: Belgium
@ -60,8 +60,8 @@ EXAMPLES = r'''
delegate_to: localhost
- name: Remove a label
msc_label:
host: msc_host
mso_label:
host: mso_host
username: admin
password: SomeSecretPassword
label: Belgium
@ -69,8 +69,8 @@ EXAMPLES = r'''
delegate_to: localhost
- name: Query a label
msc_label:
host: msc_host
mso_label:
host: mso_host
username: admin
password: SomeSecretPassword
label: Belgium
@ -79,8 +79,8 @@ EXAMPLES = r'''
register: query_result
- name: Query all labels
msc_label:
host: msc_host
mso_label:
host: mso_host
username: admin
password: SomeSecretPassword
state: query
@ -92,11 +92,11 @@ RETURN = r'''
'''
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network.aci.msc import MSCModule, msc_argument_spec, issubset
from ansible.module_utils.network.aci.mso import MSOModule, mso_argument_spec, issubset
def main():
argument_spec = msc_argument_spec()
argument_spec = mso_argument_spec()
argument_spec.update(
label=dict(type='str', required=False, aliases=['name', 'label_name']),
label_id=dict(type='str', required=False),
@ -118,24 +118,24 @@ def main():
label_type = module.params['type']
state = module.params['state']
msc = MSCModule(module)
mso = MSOModule(module)
path = 'labels'
# Query for existing object(s)
if label_id is None and label is None:
msc.existing = msc.query_objs(path)
mso.existing = mso.query_objs(path)
elif label_id is None:
msc.existing = msc.get_obj(path, displayName=label)
if msc.existing:
label_id = msc.existing['id']
mso.existing = mso.get_obj(path, displayName=label)
if mso.existing:
label_id = mso.existing['id']
elif label is None:
msc.existing = msc.get_obj(path, id=label_id)
mso.existing = mso.get_obj(path, id=label_id)
else:
msc.existing = msc.get_obj(path, id=label_id)
existing_by_name = msc.get_obj(path, displayName=label)
mso.existing = mso.get_obj(path, id=label_id)
existing_by_name = mso.get_obj(path, displayName=label)
if existing_by_name and label_id != existing_by_name['id']:
msc.fail_json(msg="Provided label '{0}' with id '{1}' does not match existing id '{2}'.".format(label, label_id, existing_by_name['id']))
mso.fail_json(msg="Provided label '{0}' with id '{1}' does not match existing id '{2}'.".format(label, label_id, existing_by_name['id']))
# If we found an existing object, continue with it
if label_id:
@ -145,15 +145,15 @@ def main():
pass
elif state == 'absent':
msc.previous = msc.existing
if msc.existing:
mso.previous = mso.existing
if mso.existing:
if module.check_mode:
msc.existing = {}
mso.existing = {}
else:
msc.existing = msc.request(path, method='DELETE')
mso.existing = mso.request(path, method='DELETE')
elif state == 'present':
msc.previous = msc.existing
mso.previous = mso.existing
payload = dict(
id=label_id,
@ -161,21 +161,21 @@ def main():
type=label_type,
)
msc.sanitize(payload, collate=True)
mso.sanitize(payload, collate=True)
if msc.existing:
if not issubset(msc.sent, msc.existing):
if mso.existing:
if not issubset(mso.sent, mso.existing):
if module.check_mode:
msc.existing = msc.proposed
mso.existing = mso.proposed
else:
msc.existing = msc.request(path, method='PUT', data=msc.sent)
mso.existing = mso.request(path, method='PUT', data=mso.sent)
else:
if module.check_mode:
msc.existing = msc.proposed
mso.existing = mso.proposed
else:
msc.existing = msc.request(path, method='POST', data=msc.sent)
mso.existing = mso.request(path, method='POST', data=mso.sent)
msc.exit_json()
mso.exit_json()
if __name__ == "__main__":

@ -13,7 +13,7 @@ ANSIBLE_METADATA = {'metadata_version': '1.1',
DOCUMENTATION = r'''
---
module: msc_role
module: mso_role
short_description: Manage roles
description:
- Manage roles on Cisco ACI Multi-Site.
@ -70,13 +70,13 @@ options:
type: str
choices: [ absent, present, query ]
default: present
extends_documentation_fragment: msc
extends_documentation_fragment: mso
'''
EXAMPLES = r'''
- name: Add a new role
msc_role:
host: msc_host
mso_role:
host: mso_host
username: admin
password: SomeSecretPassword
role: readOnly
@ -93,8 +93,8 @@ EXAMPLES = r'''
delegate_to: localhost
- name: Remove a role
msc_role:
host: msc_host
mso_role:
host: mso_host
username: admin
password: SomeSecretPassword
role: readOnly
@ -102,8 +102,8 @@ EXAMPLES = r'''
delegate_to: localhost
- name: Query a role
msc_role:
host: msc_host
mso_role:
host: mso_host
username: admin
password: SomeSecretPassword
role: readOnly
@ -112,8 +112,8 @@ EXAMPLES = r'''
register: query_result
- name: Query all roles
msc_role:
host: msc_host
mso_role:
host: mso_host
username: admin
password: SomeSecretPassword
state: query
@ -125,11 +125,11 @@ RETURN = r'''
'''
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network.aci.msc import MSCModule, msc_argument_spec, issubset
from ansible.module_utils.network.aci.mso import MSOModule, mso_argument_spec, issubset
def main():
argument_spec = msc_argument_spec()
argument_spec = mso_argument_spec()
argument_spec.update(
role=dict(type='str', required=False, aliases=['name', 'role_name']),
role_id=dict(type='str', required=False),
@ -173,24 +173,24 @@ def main():
permissions = module.params['permissions']
state = module.params['state']
msc = MSCModule(module)
mso = MSOModule(module)
path = 'roles'
# Query for existing object(s)
if role_id is None and role is None:
msc.existing = msc.query_objs(path)
mso.existing = mso.query_objs(path)
elif role_id is None:
msc.existing = msc.get_obj(path, name=role)
if msc.existing:
role_id = msc.existing['id']
mso.existing = mso.get_obj(path, name=role)
if mso.existing:
role_id = mso.existing['id']
elif role is None:
msc.existing = msc.get_obj(path, id=role_id)
mso.existing = mso.get_obj(path, id=role_id)
else:
msc.existing = msc.get_obj(path, id=role_id)
existing_by_name = msc.get_obj(path, name=role)
mso.existing = mso.get_obj(path, id=role_id)
existing_by_name = mso.get_obj(path, name=role)
if existing_by_name and role_id != existing_by_name['id']:
msc.fail_json(msg="Provided role '{0}' with id '{1}' does not match existing id '{2}'.".format(role, role_id, existing_by_name['id']))
mso.fail_json(msg="Provided role '{0}' with id '{1}' does not match existing id '{2}'.".format(role, role_id, existing_by_name['id']))
# If we found an existing object, continue with it
if role_id:
@ -200,15 +200,15 @@ def main():
pass
elif state == 'absent':
msc.previous = msc.existing
if msc.existing:
mso.previous = mso.existing
if mso.existing:
if module.check_mode:
msc.existing = {}
mso.existing = {}
else:
msc.existing = msc.request(path, method='DELETE')
mso.existing = mso.request(path, method='DELETE')
elif state == 'present':
msc.previous = msc.existing
mso.previous = mso.existing
payload = dict(
id=role_id,
@ -218,21 +218,21 @@ def main():
permissions=permissions,
)
msc.sanitize(payload, collate=True)
mso.sanitize(payload, collate=True)
if msc.existing:
if not issubset(msc.sent, msc.existing):
if mso.existing:
if not issubset(mso.sent, mso.existing):
if module.check_mode:
msc.existing = msc.proposed
mso.existing = mso.proposed
else:
msc.existing = msc.request(path, method='PUT', data=msc.sent)
mso.existing = mso.request(path, method='PUT', data=mso.sent)
else:
if module.check_mode:
msc.existing = msc.proposed
mso.existing = mso.proposed
else:
msc.existing = msc.request(path, method='POST', data=msc.sent)
mso.existing = mso.request(path, method='POST', data=mso.sent)
msc.exit_json()
mso.exit_json()
if __name__ == "__main__":

@ -12,7 +12,7 @@ ANSIBLE_METADATA = {'metadata_version': '1.1',
DOCUMENTATION = r'''
---
module: msc_schema
module: mso_schema
short_description: Manage schemas
description:
- Manage schemas on Cisco ACI Multi-Site.
@ -46,13 +46,13 @@ options:
type: str
choices: [ absent, present, query ]
default: present
extends_documentation_fragment: msc
extends_documentation_fragment: mso
'''
EXAMPLES = r'''
- name: Add a new schema
msc_schema:
host: msc_host
mso_schema:
host: mso_host
username: admin
password: SomeSecretPassword
schema: Schema 1
@ -71,8 +71,8 @@ EXAMPLES = r'''
delegate_to: localhost
- name: Remove schemas
msc_schema:
host: msc_host
mso_schema:
host: mso_host
username: admin
password: SomeSecretPassword
schema: Schema 1
@ -80,8 +80,8 @@ EXAMPLES = r'''
delegate_to: localhost
- name: Query a schema
msc_schema:
host: msc_host
mso_schema:
host: mso_host
username: admin
password: SomeSecretPassword
schema: Schema 1
@ -90,8 +90,8 @@ EXAMPLES = r'''
register: query_result
- name: Query all schemas
msc_schema:
host: msc_host
mso_schema:
host: mso_host
username: admin
password: SomeSecretPassword
state: query
@ -103,11 +103,11 @@ RETURN = r'''
'''
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network.aci.msc import MSCModule, msc_argument_spec, issubset
from ansible.module_utils.network.aci.mso import MSOModule, mso_argument_spec, issubset
def main():
argument_spec = msc_argument_spec()
argument_spec = mso_argument_spec()
argument_spec.update(
schema=dict(type='str', required=False, aliases=['name', 'schema_name']),
schema_id=dict(type='str', required=False),
@ -136,24 +136,24 @@ def main():
sites = module.params['sites']
state = module.params['state']
msc = MSCModule(module)
mso = MSOModule(module)
path = 'schemas'
# Query for existing object(s)
if schema_id is None and schema is None:
msc.existing = msc.query_objs(path)
mso.existing = mso.query_objs(path)
elif schema_id is None:
msc.existing = msc.get_obj(path, displayName=schema)
if msc.existing:
schema_id = msc.existing['id']
mso.existing = mso.get_obj(path, displayName=schema)
if mso.existing:
schema_id = mso.existing['id']
elif schema is None:
msc.existing = msc.get_obj(path, id=schema_id)
mso.existing = mso.get_obj(path, id=schema_id)
else:
msc.existing = msc.get_obj(path, id=schema_id)
existing_by_name = msc.get_obj(path, displayName=schema)
mso.existing = mso.get_obj(path, id=schema_id)
existing_by_name = mso.get_obj(path, displayName=schema)
if existing_by_name and schema_id != existing_by_name['id']:
msc.fail_json(msg="Provided schema '{1}' with id '{2}' does not match existing id '{3}'.".format(schema, schema_id, existing_by_name['id']))
mso.fail_json(msg="Provided schema '{1}' with id '{2}' does not match existing id '{3}'.".format(schema, schema_id, existing_by_name['id']))
if schema_id:
path = 'schemas/{id}'.format(id=schema_id)
@ -162,15 +162,15 @@ def main():
pass
elif state == 'absent':
msc.previous = msc.existing
if msc.existing:
mso.previous = mso.existing
if mso.existing:
if module.check_mode:
msc.existing = {}
mso.existing = {}
else:
msc.existing = msc.request(path, method='DELETE')
mso.existing = mso.request(path, method='DELETE')
elif state == 'present':
msc.previous = msc.existing
mso.previous = mso.existing
payload = dict(
id=schema_id,
@ -179,21 +179,21 @@ def main():
sites=sites,
)
msc.sanitize(payload, collate=True)
mso.sanitize(payload, collate=True)
if msc.existing:
if not issubset(msc.sent, msc.existing):
if mso.existing:
if not issubset(mso.sent, mso.existing):
if module.check_mode:
msc.existing = msc.proposed
mso.existing = mso.proposed
else:
msc.existing = msc.request(path, method='PUT', data=msc.sent)
mso.existing = mso.request(path, method='PUT', data=mso.sent)
else:
if module.check_mode:
msc.existing = msc.proposed
mso.existing = mso.proposed
else:
msc.existing = msc.request(path, method='POST', data=msc.sent)
mso.existing = mso.request(path, method='POST', data=mso.sent)
msc.exit_json()
mso.exit_json()
if __name__ == "__main__":

@ -13,7 +13,7 @@ ANSIBLE_METADATA = {'metadata_version': '1.1',
DOCUMENTATION = r'''
---
module: msc_site
module: mso_site
short_description: Manage sites
description:
- Manage sites on Cisco ACI Multi-Site.
@ -76,18 +76,18 @@ options:
type: str
choices: [ absent, present, query ]
default: present
extends_documentation_fragment: msc
extends_documentation_fragment: mso
'''
EXAMPLES = r'''
- name: Add a new site
msc_site:
host: msc_host
mso_site:
host: mso_host
username: admin
password: SomeSecretPassword
site: north_europe
description: North European Datacenter
apic_username: msc_admin
apic_username: mso_admin
apic_password: AnotherSecretPassword
apic_site_id: 12
urls:
@ -105,8 +105,8 @@ EXAMPLES = r'''
delegate_to: localhost
- name: Remove a site
msc_site:
host: msc_host
mso_site:
host: mso_host
username: admin
password: SomeSecretPassword
site: north_europe
@ -114,8 +114,8 @@ EXAMPLES = r'''
delegate_to: localhost
- name: Query a site
msc_site:
host: msc_host
mso_site:
host: mso_host
username: admin
password: SomeSecretPassword
site: north_europe
@ -124,8 +124,8 @@ EXAMPLES = r'''
register: query_result
- name: Query all sites
msc_site:
host: msc_host
mso_site:
host: mso_host
username: admin
password: SomeSecretPassword
state: query
@ -137,7 +137,7 @@ RETURN = r'''
'''
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network.aci.msc import MSCModule, msc_argument_spec, issubset
from ansible.module_utils.network.aci.mso import MSOModule, mso_argument_spec, issubset
def main():
@ -146,7 +146,7 @@ def main():
longitude=dict(type='float'),
)
argument_spec = msc_argument_spec()
argument_spec = mso_argument_spec()
argument_spec.update(
apic_password=dict(type='str', no_log=True),
apic_site_id=dict(type='str'),
@ -180,27 +180,27 @@ def main():
state = module.params['state']
urls = module.params['urls']
msc = MSCModule(module)
mso = MSOModule(module)
path = 'sites'
# Convert labels
labels = msc.lookup_labels(module.params['labels'], 'site')
labels = mso.lookup_labels(module.params['labels'], 'site')
# Query for msc.existing object(s)
# Query for mso.existing object(s)
if site_id is None and site is None:
msc.existing = msc.query_objs(path)
mso.existing = mso.query_objs(path)
elif site_id is None:
msc.existing = msc.get_obj(path, name=site)
if msc.existing:
site_id = msc.existing['id']
mso.existing = mso.get_obj(path, name=site)
if mso.existing:
site_id = mso.existing['id']
elif site is None:
msc.existing = msc.get_obj(path, id=site_id)
mso.existing = mso.get_obj(path, id=site_id)
else:
msc.existing = msc.get_obj(path, id=site_id)
existing_by_name = msc.get_obj(path, name=site)
mso.existing = mso.get_obj(path, id=site_id)
existing_by_name = mso.get_obj(path, name=site)
if existing_by_name and site_id != existing_by_name['id']:
msc.fail_json(msg="Provided site '{0}' with id '{1}' does not match existing id '{2}'.".format(site, site_id, existing_by_name['id']))
mso.fail_json(msg="Provided site '{0}' with id '{1}' does not match existing id '{2}'.".format(site, site_id, existing_by_name['id']))
# If we found an existing object, continue with it
if site_id:
@ -210,15 +210,15 @@ def main():
pass
elif state == 'absent':
msc.previous = msc.existing
if msc.existing:
mso.previous = mso.existing
if mso.existing:
if module.check_mode:
msc.existing = {}
mso.existing = {}
else:
msc.existing = msc.request(path, method='DELETE', qs=dict(force='true'))
mso.existing = mso.request(path, method='DELETE', qs=dict(force='true'))
elif state == 'present':
msc.previous = msc.existing
mso.previous = mso.existing
payload = dict(
apicSiteId=apic_site_id,
@ -236,24 +236,24 @@ def main():
long=longitude,
)
msc.sanitize(payload, collate=True)
mso.sanitize(payload, collate=True)
if msc.existing:
if not issubset(msc.sent, msc.existing):
if mso.existing:
if not issubset(mso.sent, mso.existing):
if module.check_mode:
msc.existing = msc.proposed
mso.existing = mso.proposed
else:
msc.existing = msc.request(path, method='PUT', data=msc.sent)
mso.existing = mso.request(path, method='PUT', data=mso.sent)
else:
if module.check_mode:
msc.existing = msc.proposed
mso.existing = mso.proposed
else:
msc.existing = msc.request(path, method='POST', data=msc.sent)
mso.existing = mso.request(path, method='POST', data=mso.sent)
if 'password' in msc.existing:
msc.existing['password'] = '******'
if 'password' in mso.existing:
mso.existing['password'] = '******'
msc.exit_json()
mso.exit_json()
if __name__ == "__main__":

@ -13,7 +13,7 @@ ANSIBLE_METADATA = {'metadata_version': '1.1',
DOCUMENTATION = r'''
---
module: msc_tenant
module: mso_tenant
short_description: Manage tenants
description:
- Manage tenants on Cisco ACI Multi-Site.
@ -43,13 +43,13 @@ options:
type: str
users:
description:
- A list of allowed users for this tenant.
- Using this property will replace any existing allowed users.
- A list of associated users for this tenant.
- Using this property will replace any existing associated users.
type: list
sites:
description:
- A list of allowed sites for this tenant.
- Using this property will replace any existing allowed sites.
- A list of associated sites for this tenant.
- Using this property will replace any existing associated sites.
type: list
state:
description:
@ -58,13 +58,13 @@ options:
type: str
choices: [ absent, present, query ]
default: present
extends_documentation_fragment: msc
extends_documentation_fragment: mso
'''
EXAMPLES = r'''
- name: Add a new tenant
msc_tenant:
host: msc_host
mso_tenant:
host: mso_host
username: admin
password: SomeSecretPassword
tenant: north_europe
@ -75,8 +75,8 @@ EXAMPLES = r'''
delegate_to: localhost
- name: Remove a tenant
msc_tenant:
host: msc_host
mso_tenant:
host: mso_host
username: admin
password: SomeSecretPassword
tenant: north_europe
@ -84,8 +84,8 @@ EXAMPLES = r'''
delegate_to: localhost
- name: Query a tenant
msc_tenant:
host: msc_host
mso_tenant:
host: mso_host
username: admin
password: SomeSecretPassword
tenant: north_europe
@ -94,8 +94,8 @@ EXAMPLES = r'''
register: query_result
- name: Query all tenants
msc_tenant:
host: msc_host
mso_tenant:
host: mso_host
username: admin
password: SomeSecretPassword
state: query
@ -107,11 +107,11 @@ RETURN = r'''
'''
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network.aci.msc import MSCModule, msc_argument_spec, issubset
from ansible.module_utils.network.aci.mso import MSOModule, mso_argument_spec, issubset
def main():
argument_spec = msc_argument_spec()
argument_spec = mso_argument_spec()
argument_spec.update(
description=dict(type='str'),
display_name=dict(type='str'),
@ -137,28 +137,28 @@ def main():
tenant_id = module.params['tenant_id']
state = module.params['state']
msc = MSCModule(module)
mso = MSOModule(module)
# Convert sites and users
sites = msc.lookup_sites(module.params['sites'])
users = msc.lookup_users(module.params['users'])
sites = mso.lookup_sites(module.params['sites'])
users = mso.lookup_users(module.params['users'])
path = 'tenants'
# Query for existing object(s)
if tenant_id is None and tenant is None:
msc.existing = msc.query_objs(path)
mso.existing = mso.query_objs(path)
elif tenant_id is None:
msc.existing = msc.get_obj(path, name=tenant)
if msc.existing:
tenant_id = msc.existing['id']
mso.existing = mso.get_obj(path, name=tenant)
if mso.existing:
tenant_id = mso.existing['id']
elif tenant is None:
msc.existing = msc.get_obj(path, id=tenant_id)
mso.existing = mso.get_obj(path, id=tenant_id)
else:
msc.existing = msc.get_obj(path, id=tenant_id)
existing_by_name = msc.get_obj(path, name=tenant)
mso.existing = mso.get_obj(path, id=tenant_id)
existing_by_name = mso.get_obj(path, name=tenant)
if existing_by_name and tenant_id != existing_by_name['id']:
msc.fail_json(msg="Provided tenant '{0}' with id '{1}' does not match existing id '{2}'.".format(tenant, tenant_id, existing_by_name['id']))
mso.fail_json(msg="Provided tenant '{0}' with id '{1}' does not match existing id '{2}'.".format(tenant, tenant_id, existing_by_name['id']))
# If we found an existing object, continue with it
if tenant_id:
@ -168,15 +168,15 @@ def main():
pass
elif state == 'absent':
msc.previous = msc.existing
if msc.existing:
mso.previous = mso.existing
if mso.existing:
if module.check_mode:
msc.existing = {}
mso.existing = {}
else:
msc.existing = msc.request(path, method='DELETE')
mso.existing = mso.request(path, method='DELETE')
elif state == 'present':
msc.previous = msc.existing
mso.previous = mso.existing
payload = dict(
description=description,
@ -187,29 +187,29 @@ def main():
userAssociations=users,
)
msc.sanitize(payload, collate=True)
mso.sanitize(payload, collate=True)
# Ensure displayName is not undefined
if msc.sent.get('displayName') is None:
msc.sent['displayName'] = tenant
if mso.sent.get('displayName') is None:
mso.sent['displayName'] = tenant
# Ensure tenant has at least admin user
if msc.sent.get('userAssociations') is None:
msc.sent['userAssociations'] = [dict(userId="0000ffff0000000000000020")]
if mso.sent.get('userAssociations') is None:
mso.sent['userAssociations'] = [dict(userId="0000ffff0000000000000020")]
if msc.existing:
if not issubset(msc.sent, msc.existing):
if mso.existing:
if not issubset(mso.sent, mso.existing):
if module.check_mode:
msc.existing = msc.proposed
mso.existing = mso.proposed
else:
msc.existing = msc.request(path, method='PUT', data=msc.sent)
mso.existing = mso.request(path, method='PUT', data=mso.sent)
else:
if module.check_mode:
msc.existing = msc.proposed
mso.existing = mso.proposed
else:
msc.existing = msc.request(path, method='POST', data=msc.sent)
mso.existing = mso.request(path, method='POST', data=mso.sent)
msc.exit_json()
mso.exit_json()
if __name__ == "__main__":

@ -13,7 +13,7 @@ ANSIBLE_METADATA = {'metadata_version': '1.1',
DOCUMENTATION = r'''
---
module: msc_user
module: mso_user
short_description: Manage users
description:
- Manage users on Cisco ACI Multi-Site.
@ -80,13 +80,13 @@ options:
notes:
- A default installation of ACI Multi-Site ships with admin password 'we1come!' which requires a password change on first login.
See the examples of how to change the 'admin' password using Ansible.
extends_documentation_fragment: msc
extends_documentation_fragment: mso
'''
EXAMPLES = r'''
- name: Update initial admin password
msc_user:
host: msc_host
mso_user:
host: mso_host
username: admin
password: we1come!
user_name: admin
@ -95,8 +95,8 @@ EXAMPLES = r'''
delegate_to: localhost
- name: Add a new user
msc_user:
host: msc_host
mso_user:
host: mso_host
username: admin
password: SomeSecretPassword
user_name: dag
@ -109,8 +109,8 @@ EXAMPLES = r'''
delegate_to: localhost
- name: Remove a user
msc_user:
host: msc_host
mso_user:
host: mso_host
username: admin
password: SomeSecretPassword
user_name: dag
@ -118,8 +118,8 @@ EXAMPLES = r'''
delegate_to: localhost
- name: Query a user
msc_user:
host: msc_host
mso_user:
host: mso_host
username: admin
password: SomeSecretPassword
user_name: dag
@ -128,8 +128,8 @@ EXAMPLES = r'''
register: query_result
- name: Query all users
msc_user:
host: msc_host
mso_user:
host: mso_host
username: admin
password: SomeSecretPassword
state: query
@ -140,11 +140,11 @@ EXAMPLES = r'''
RETURN = r''' # '''
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network.aci.msc import MSCModule, msc_argument_spec, issubset
from ansible.module_utils.network.aci.mso import MSOModule, mso_argument_spec, issubset
def main():
argument_spec = msc_argument_spec()
argument_spec = mso_argument_spec()
argument_spec.update(
user_id=dict(type='str', required=False),
user=dict(type='str', required=False, aliases=['name', 'user_name']),
@ -179,27 +179,27 @@ def main():
account_status = module.params['account_status']
state = module.params['state']
msc = MSCModule(module)
mso = MSOModule(module)
roles = msc.lookup_roles(module.params['roles'])
domain = msc.lookup_domain(module.params['domain'])
roles = mso.lookup_roles(module.params['roles'])
domain = mso.lookup_domain(module.params['domain'])
path = 'users'
# Query for existing object(s)
if user_id is None and user_name is None:
msc.existing = msc.query_objs(path)
mso.existing = mso.query_objs(path)
elif user_id is None:
msc.existing = msc.get_obj(path, username=user_name)
if msc.existing:
user_id = msc.existing['id']
mso.existing = mso.get_obj(path, username=user_name)
if mso.existing:
user_id = mso.existing['id']
elif user_name is None:
msc.existing = msc.get_obj(path, id=user_id)
mso.existing = mso.get_obj(path, id=user_id)
else:
msc.existing = msc.get_obj(path, id=user_id)
existing_by_name = msc.get_obj(path, username=user_name)
mso.existing = mso.get_obj(path, id=user_id)
existing_by_name = mso.get_obj(path, username=user_name)
if existing_by_name and user_id != existing_by_name['id']:
msc.fail_json(msg="Provided user '{0}' with id '{1}' does not match existing id '{2}'.".format(user_name, user_id, existing_by_name['id']))
mso.fail_json(msg="Provided user '{0}' with id '{1}' does not match existing id '{2}'.".format(user_name, user_id, existing_by_name['id']))
# If we found an existing object, continue with it
if user_id:
@ -209,15 +209,15 @@ def main():
pass
elif state == 'absent':
msc.previous = msc.existing
if msc.existing:
mso.previous = mso.existing
if mso.existing:
if module.check_mode:
msc.existing = {}
mso.existing = {}
else:
msc.existing = msc.request(path, method='DELETE')
mso.existing = mso.request(path, method='DELETE')
elif state == 'present':
msc.previous = msc.existing
mso.previous = mso.existing
payload = dict(
id=user_id,
@ -234,29 +234,29 @@ def main():
# remote=True,
)
msc.sanitize(payload, collate=True)
mso.sanitize(payload, collate=True)
if msc.sent.get('accountStatus') is None:
msc.sent['accountStatus'] = 'active'
if mso.sent.get('accountStatus') is None:
mso.sent['accountStatus'] = 'active'
if msc.existing:
if not issubset(msc.sent, msc.existing):
# NOTE: Since MSC always returns '******' as password, we need to assume a change
if 'password' in msc.proposed:
msc.module.warn("A password change is assumed, as the MSC REST API does not return passwords we do not know.")
msc.result['changed'] = True
if mso.existing:
if not issubset(mso.sent, mso.existing):
# NOTE: Since MSO always returns '******' as password, we need to assume a change
if 'password' in mso.proposed:
mso.module.warn("A password change is assumed, as the MSO REST API does not return passwords we do not know.")
mso.result['changed'] = True
if module.check_mode:
msc.existing = msc.proposed
mso.existing = mso.proposed
else:
msc.existing = msc.request(path, method='PUT', data=msc.sent)
mso.existing = mso.request(path, method='PUT', data=mso.sent)
else:
if module.check_mode:
msc.existing = msc.proposed
mso.existing = mso.proposed
else:
msc.existing = msc.request(path, method='POST', data=msc.sent)
mso.existing = mso.request(path, method='POST', data=mso.sent)
msc.exit_json()
mso.exit_json()
if __name__ == "__main__":

@ -24,15 +24,15 @@ aci_use_proxy=no
[aci]
localhost ansible_ssh_host=127.0.0.1 ansible_connection=local
[msc:vars]
msc_hostname=your-msc-1
msc_username=admin
msc_password=your-msc-password
msc_validate_certs=no
msc_use_ssl=yes
msc_use_proxy=no
[mso:vars]
mso_hostname=your-mso-1
mso_username=admin
mso_password=your-mso-password
mso_validate_certs=no
mso_use_ssl=yes
mso_use_proxy=no
[msc]
[mso]
localhost ansible_ssh_host=127.0.0.1 ansible_connection=local
###

@ -19,7 +19,7 @@ iosxr
ironware
junos
meraki
msc
mso
net
netconf
nxos

@ -1,29 +1,29 @@
# Test code for the MSC modules
# Test code for the MSO modules
# Copyright: (c) 2018, Dag Wieers (@dagwieers) <dag@wieers.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
- name: Test that we have an ACI MultiSite host, username and password
fail:
msg: 'Please define the following variables: msc_hostname, msc_username and msc_password.'
when: msc_hostname is not defined or msc_username is not defined or msc_password is not defined
msg: 'Please define the following variables: mso_hostname, mso_username and mso_password.'
when: mso_hostname is not defined or mso_username is not defined or mso_password is not defined
# CLEAN ENVIRONMENT
- name: Remove label ansible_test2
msc_label: &label_absent
host: '{{ msc_hostname }}'
username: '{{ msc_username }}'
password: '{{ msc_password }}'
validate_certs: '{{ msc_validate_certs | default(false) }}'
use_ssl: '{{ msc_use_ssl | default(true) }}'
use_proxy: '{{ msc_use_proxy | default(true) }}'
output_level: '{{ msc_output_level | default("info") }}'
mso_label: &label_absent
host: '{{ mso_hostname }}'
username: '{{ mso_username }}'
password: '{{ mso_password }}'
validate_certs: '{{ mso_validate_certs | default(false) }}'
use_ssl: '{{ mso_use_ssl | default(true) }}'
use_proxy: '{{ mso_use_proxy | default(true) }}'
output_level: '{{ mso_output_level | default("info") }}'
label: ansible_test2
state: absent
- name: Remove label ansible_test
msc_label:
mso_label:
<<: *label_absent
label: ansible_test
register: cm_remove_label
@ -31,14 +31,14 @@
# ADD LABEL
- name: Add label (check_mode)
msc_label: &label_present
host: '{{ msc_hostname }}'
username: '{{ msc_username }}'
password: '{{ msc_password }}'
validate_certs: '{{ msc_validate_certs | default(false) }}'
use_ssl: '{{ msc_use_ssl | default(true) }}'
use_proxy: '{{ msc_use_proxy | default(true) }}'
output_level: '{{ msc_output_level | default("info") }}'
mso_label: &label_present
host: '{{ mso_hostname }}'
username: '{{ mso_username }}'
password: '{{ mso_password }}'
validate_certs: '{{ mso_validate_certs | default(false) }}'
use_ssl: '{{ mso_use_ssl | default(true) }}'
use_proxy: '{{ mso_use_proxy | default(true) }}'
output_level: '{{ mso_output_level | default("info") }}'
label: ansible_test
state: present
check_mode: yes
@ -54,7 +54,7 @@
- cm_add_label.current.type == 'site'
- name: Add label (normal mode)
msc_label: *label_present
mso_label: *label_present
register: nm_add_label
- name: nm_Verify add_label
@ -67,7 +67,7 @@
- nm_add_label.current.type == 'site'
- name: Add label again (check_mode)
msc_label: *label_present
mso_label: *label_present
check_mode: yes
register: cm_add_label_again
@ -82,7 +82,7 @@
- cm_add_label_again.current.type == 'site'
- name: Add label again (normal mode)
msc_label: *label_present
mso_label: *label_present
register: nm_add_label_again
- name: Verify nm_add_label_again
@ -98,7 +98,7 @@
# CHANGE LABEL
- name: Change label (check_mode)
msc_label:
mso_label:
<<: *label_present
label_id: '{{ nm_add_label.current.id }}'
label: ansible_test2
@ -114,7 +114,7 @@
- cm_change_label.current.type == 'site'
- name: Change label (normal mode)
msc_label:
mso_label:
<<: *label_present
label_id: '{{ nm_add_label.current.id }}'
label: ansible_test2
@ -130,7 +130,7 @@
- nm_change_label.current.type == 'site'
- name: Change label again (check_mode)
msc_label:
mso_label:
<<: *label_present
label_id: '{{ nm_add_label.current.id }}'
label: ansible_test2
@ -146,7 +146,7 @@
- cm_change_label_again.current.type == 'site'
- name: Change label again (normal mode)
msc_label:
mso_label:
<<: *label_present
label_id: '{{ nm_add_label.current.id }}'
label: ansible_test2
@ -163,20 +163,20 @@
# QUERY ALL LABELS
- name: Query all labels (check_mode)
msc_label: &label_query
host: '{{ msc_hostname }}'
username: '{{ msc_username }}'
password: '{{ msc_password }}'
validate_certs: '{{ msc_validate_certs | default(false) }}'
use_ssl: '{{ msc_use_ssl | default(true) }}'
use_proxy: '{{ msc_use_proxy | default(true) }}'
output_level: '{{ msc_output_level | default("info") }}'
mso_label: &label_query
host: '{{ mso_hostname }}'
username: '{{ mso_username }}'
password: '{{ mso_password }}'
validate_certs: '{{ mso_validate_certs | default(false) }}'
use_ssl: '{{ mso_use_ssl | default(true) }}'
use_proxy: '{{ mso_use_proxy | default(true) }}'
output_level: '{{ mso_output_level | default("info") }}'
state: query
check_mode: yes
register: cm_query_all_labels
- name: Query all labels (normal mode)
msc_label: *label_query
mso_label: *label_query
register: nm_query_all_labels
- name: Verify query_all_labels
@ -190,14 +190,14 @@
# QUERY A LABEL
- name: Query our label
msc_label:
mso_label:
<<: *label_query
label: ansible_test2
check_mode: yes
register: cm_query_label
- name: Query our label
msc_label:
mso_label:
<<: *label_query
label: ansible_test2
register: nm_query_label
@ -218,7 +218,7 @@
# REMOVE LABEL
- name: Remove label (check_mode)
msc_label: *label_absent
mso_label: *label_absent
check_mode: yes
register: cm_remove_label
@ -229,7 +229,7 @@
- cm_remove_label.current == {}
- name: Remove label (normal mode)
msc_label: *label_absent
mso_label: *label_absent
register: nm_remove_label
- name: Verify nm_remove_label
@ -239,7 +239,7 @@
- nm_remove_label.current == {}
- name: Remove label again (check_mode)
msc_label: *label_absent
mso_label: *label_absent
check_mode: yes
register: cm_remove_label_again
@ -250,7 +250,7 @@
- cm_remove_label_again.current == {}
- name: Remove label again (normal mode)
msc_label: *label_absent
mso_label: *label_absent
register: nm_remove_label_again
- name: Verify nm_remove_label_again
@ -262,14 +262,14 @@
# QUERY NON-EXISTING LABEL
- name: Query non-existing label (check_mode)
msc_label:
mso_label:
<<: *label_query
label: ansible_test
check_mode: yes
register: cm_query_non_label
- name: Query non-existing label (normal mode)
msc_label:
mso_label:
<<: *label_query
label: ansible_test
register: nm_query_non_label

@ -1,29 +1,29 @@
# Test code for the MSC modules
# Test code for the MSO modules
# Copyright: (c) 2018, Dag Wieers (@dagwieers) <dag@wieers.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
- name: Test that we have an ACI MultiSite host, username and password
fail:
msg: 'Please define the following variables: msc_hostname, msc_username and msc_password.'
when: msc_hostname is not defined or msc_username is not defined or msc_password is not defined
msg: 'Please define the following variables: mso_hostname, mso_username and mso_password.'
when: mso_hostname is not defined or mso_username is not defined or mso_password is not defined
# CLEAN ENVIRONMENT
- name: Remove role ansible_test2
msc_role: &role_absent
host: '{{ msc_hostname }}'
username: '{{ msc_username }}'
password: '{{ msc_password }}'
validate_certs: '{{ msc_validate_certs | default(false) }}'
use_ssl: '{{ msc_use_ssl | default(true) }}'
use_proxy: '{{ msc_use_proxy | default(true) }}'
output_level: '{{ msc_output_level | default("info") }}'
mso_role: &role_absent
host: '{{ mso_hostname }}'
username: '{{ mso_username }}'
password: '{{ mso_password }}'
validate_certs: '{{ mso_validate_certs | default(false) }}'
use_ssl: '{{ mso_use_ssl | default(true) }}'
use_proxy: '{{ mso_use_proxy | default(true) }}'
output_level: '{{ mso_output_level | default("info") }}'
role: ansible_test2
state: absent
- name: Remove role ansible_test
msc_role:
mso_role:
<<: *role_absent
role: ansible_test
register: cm_remove_role
@ -31,14 +31,14 @@
# ADD ROLE
- name: Add role (check_mode)
msc_role: &role_present
host: '{{ msc_hostname }}'
username: '{{ msc_username }}'
password: '{{ msc_password }}'
validate_certs: '{{ msc_validate_certs | default(false) }}'
use_ssl: '{{ msc_use_ssl | default(true) }}'
use_proxy: '{{ msc_use_proxy | default(true) }}'
output_level: '{{ msc_output_level | default("info") }}'
mso_role: &role_present
host: '{{ mso_hostname }}'
username: '{{ mso_username }}'
password: '{{ mso_password }}'
validate_certs: '{{ mso_validate_certs | default(false) }}'
use_ssl: '{{ mso_use_ssl | default(true) }}'
use_proxy: '{{ mso_use_proxy | default(true) }}'
output_level: '{{ mso_output_level | default("info") }}'
role: ansible_test
description: Ansible test role
permissions: view-sites
@ -56,7 +56,7 @@
- cm_add_role.current.id is not defined
- name: Add role (normal mode)
msc_role: *role_present
mso_role: *role_present
register: nm_add_role
- name: nm_Verify add_role
@ -69,7 +69,7 @@
- nm_add_role.current.id is defined
- name: Add role again (check_mode)
msc_role: *role_present
mso_role: *role_present
check_mode: yes
register: cm_add_role_again
@ -84,7 +84,7 @@
- cm_add_role_again.current.id == nm_add_role.current.id
- name: Add role again (normal mode)
msc_role: *role_present
mso_role: *role_present
register: nm_add_role_again
- name: Verify nm_add_role_again
@ -100,7 +100,7 @@
# CHANGE ROLE
- name: Change role (check_mode)
msc_role:
mso_role:
<<: *role_present
role_id: '{{ nm_add_role.current.id }}'
role: ansible_test2
@ -117,7 +117,7 @@
- cm_change_role.current.id == nm_add_role.current.id
- name: Change role (normal mode)
msc_role:
mso_role:
<<: *role_present
role_id: '{{ nm_add_role.current.id }}'
role: ansible_test2
@ -134,7 +134,7 @@
- nm_change_role.current.id == nm_add_role.current.id
- name: Change role again (check_mode)
msc_role:
mso_role:
<<: *role_present
role_id: '{{ nm_add_role.current.id }}'
role: ansible_test2
@ -151,7 +151,7 @@
- cm_change_role_again.current.id == nm_add_role.current.id
- name: Change role again (normal mode)
msc_role:
mso_role:
<<: *role_present
role_id: '{{ nm_add_role.current.id }}'
role: ansible_test2
@ -169,20 +169,20 @@
# QUERY ALL ROLES
- name: Query all roles (check_mode)
msc_role: &role_query
host: '{{ msc_hostname }}'
username: '{{ msc_username }}'
password: '{{ msc_password }}'
validate_certs: '{{ msc_validate_certs | default(false) }}'
use_ssl: '{{ msc_use_ssl | default(true) }}'
use_proxy: '{{ msc_use_proxy | default(true) }}'
output_level: '{{ msc_output_level | default("info") }}'
mso_role: &role_query
host: '{{ mso_hostname }}'
username: '{{ mso_username }}'
password: '{{ mso_password }}'
validate_certs: '{{ mso_validate_certs | default(false) }}'
use_ssl: '{{ mso_use_ssl | default(true) }}'
use_proxy: '{{ mso_use_proxy | default(true) }}'
output_level: '{{ mso_output_level | default("info") }}'
state: query
check_mode: yes
register: cm_query_all_roles
- name: Query all roles (normal mode)
msc_role: *role_query
mso_role: *role_query
register: nm_query_all_roles
- name: Verify query_all_roles
@ -196,14 +196,14 @@
# QUERY A ROLE
- name: Query our role
msc_role:
mso_role:
<<: *role_query
role: ansible_test2
check_mode: yes
register: cm_query_role
- name: Query our role
msc_role:
mso_role:
<<: *role_query
role: ansible_test2
register: nm_query_role
@ -224,7 +224,7 @@
# REMOVE ROLE
- name: Remove role (check_mode)
msc_role: *role_absent
mso_role: *role_absent
check_mode: yes
register: cm_remove_role
@ -235,7 +235,7 @@
- cm_remove_role.current == {}
- name: Remove role (normal mode)
msc_role: *role_absent
mso_role: *role_absent
register: nm_remove_role
- name: Verify nm_remove_role
@ -245,7 +245,7 @@
- nm_remove_role.current == {}
- name: Remove role again (check_mode)
msc_role: *role_absent
mso_role: *role_absent
check_mode: yes
register: cm_remove_role_again
@ -256,7 +256,7 @@
- cm_remove_role_again.current == {}
- name: Remove role again (normal mode)
msc_role: *role_absent
mso_role: *role_absent
register: nm_remove_role_again
- name: Verify nm_remove_role_again
@ -268,14 +268,14 @@
# QUERY NON-EXISTING ROLE
- name: Query non-existing role (check_mode)
msc_role:
mso_role:
<<: *role_query
role: ansible_test
check_mode: yes
register: cm_query_non_role
- name: Query non-existing role (normal mode)
msc_role:
mso_role:
<<: *role_query
role: ansible_test
register: nm_query_non_role

@ -1,45 +1,45 @@
# Test code for the MSC modules
# Test code for the MSO modules
# Copyright: (c) 2018, Dag Wieers (@dagwieers) <dag@wieers.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
- name: Test that we have an ACI MultiSite host, username and password
fail:
msg: 'Please define the following variables: msc_hostname, msc_username and msc_password.'
when: msc_hostname is not defined or msc_username is not defined or msc_password is not defined
msg: 'Please define the following variables: mso_hostname, mso_username and mso_password.'
when: mso_hostname is not defined or mso_username is not defined or mso_password is not defined
# CLEAN ENVIRONMENT
- name: Remove site 2
msc_site: &site_absent
host: '{{ msc_hostname }}'
username: '{{ msc_username }}'
password: '{{ msc_password }}'
validate_certs: '{{ msc_validate_certs | default(false) }}'
use_ssl: '{{ msc_use_ssl | default(true) }}'
use_proxy: '{{ msc_use_proxy | default(true) }}'
output_level: '{{ msc_output_level | default("info") }}'
site: '{{ msc_site | default("ansible_test") }}_2'
mso_site: &site_absent
host: '{{ mso_hostname }}'
username: '{{ mso_username }}'
password: '{{ mso_password }}'
validate_certs: '{{ mso_validate_certs | default(false) }}'
use_ssl: '{{ mso_use_ssl | default(true) }}'
use_proxy: '{{ mso_use_proxy | default(true) }}'
output_level: '{{ mso_output_level | default("info") }}'
site: '{{ mso_site | default("ansible_test") }}_2'
state: absent
- name: Remove site
msc_site:
mso_site:
<<: *site_absent
site: '{{ msc_site | default("ansible_test") }}'
site: '{{ mso_site | default("ansible_test") }}'
register: cm_remove_site
# ADD SITE
- name: Add site (check_mode)
msc_site: &site_present
host: '{{ msc_hostname }}'
username: '{{ msc_username }}'
password: '{{ msc_password }}'
validate_certs: '{{ msc_validate_certs | default(false) }}'
use_ssl: '{{ msc_use_ssl | default(true) }}'
use_proxy: '{{ msc_use_proxy | default(true) }}'
output_level: '{{ msc_output_level | default("info") }}'
site: '{{ msc_site | default("ansible_test") }}'
mso_site: &site_present
host: '{{ mso_hostname }}'
username: '{{ mso_username }}'
password: '{{ mso_password }}'
validate_certs: '{{ mso_validate_certs | default(false) }}'
use_ssl: '{{ mso_use_ssl | default(true) }}'
use_proxy: '{{ mso_use_proxy | default(true) }}'
output_level: '{{ mso_output_level | default("info") }}'
site: '{{ mso_site | default("ansible_test") }}'
apic_username: admin
apic_password: '{{ apic_password }}'
apic_site_id: 101
@ -62,10 +62,10 @@
- cm_add_site is changed
- cm_add_site.previous == {}
- cm_add_site.current.id is not defined
- cm_add_site.current.name == msc_site|default("ansible_test")
- cm_add_site.current.name == mso_site|default("ansible_test")
- name: Add site (normal mode)
msc_site: *site_present
mso_site: *site_present
register: nm_add_site
- name: nm_Verify add_site
@ -74,10 +74,10 @@
- nm_add_site is changed
- nm_add_site.previous == {}
- nm_add_site.current.id is defined
- nm_add_site.current.name == msc_site|default("ansible_test")
- nm_add_site.current.name == mso_site|default("ansible_test")
- name: Add site again (check_mode)
msc_site: *site_present
mso_site: *site_present
check_mode: yes
register: cm_add_site_again
@ -85,29 +85,29 @@
assert:
that:
- cm_add_site_again is not changed
- cm_add_site_again.previous.name == msc_site|default("ansible_test")
- cm_add_site_again.previous.name == mso_site|default("ansible_test")
- cm_add_site_again.current.id == nm_add_site.current.id
- cm_add_site_again.current.name == msc_site|default("ansible_test")
- cm_add_site_again.current.name == mso_site|default("ansible_test")
- name: Add site again (normal mode)
msc_site: *site_present
mso_site: *site_present
register: nm_add_site_again
- name: Verify nm_add_site_again
assert:
that:
- nm_add_site_again is not changed
- nm_add_site_again.previous.name == msc_site|default("ansible_test")
- nm_add_site_again.previous.name == mso_site|default("ansible_test")
- nm_add_site_again.current.id == nm_add_site.current.id
- nm_add_site_again.current.name == msc_site|default("ansible_test")
- nm_add_site_again.current.name == mso_site|default("ansible_test")
# CHANGE SITE
- name: Change site (check_mode)
msc_site:
mso_site:
<<: *site_present
site_id: '{{ nm_add_site.current.id }}'
site: '{{ msc_site | default("ansible_test") }}_2'
site: '{{ mso_site | default("ansible_test") }}_2'
check_mode: yes
register: cm_change_site
@ -116,13 +116,13 @@
that:
- cm_change_site is changed
- cm_change_site.current.id == nm_add_site.current.id
- cm_change_site.current.name == '{{ msc_site | default("ansible_test") }}_2'
- cm_change_site.current.name == '{{ mso_site | default("ansible_test") }}_2'
- name: Change site (normal mode)
msc_site:
mso_site:
<<: *site_present
site_id: '{{ nm_add_site.current.id }}'
site: '{{ msc_site | default("ansible_test") }}_2'
site: '{{ mso_site | default("ansible_test") }}_2'
output_level: debug
register: nm_change_site
@ -131,13 +131,13 @@
that:
- nm_change_site is changed
- nm_change_site.current.id == nm_add_site.current.id
- nm_change_site.current.name == '{{ msc_site | default("ansible_test") }}_2'
- nm_change_site.current.name == '{{ mso_site | default("ansible_test") }}_2'
- name: Change site again (check_mode)
msc_site:
mso_site:
<<: *site_present
site_id: '{{ nm_add_site.current.id }}'
site: '{{ msc_site | default("ansible_test") }}_2'
site: '{{ mso_site | default("ansible_test") }}_2'
check_mode: yes
register: cm_change_site_again
@ -146,13 +146,13 @@
that:
- cm_change_site_again is not changed
- cm_change_site_again.current.id == nm_add_site.current.id
- cm_change_site_again.current.name == '{{ msc_site | default("ansible_test") }}_2'
- cm_change_site_again.current.name == '{{ mso_site | default("ansible_test") }}_2'
- name: Change site again (normal mode)
msc_site:
mso_site:
<<: *site_present
site_id: '{{ nm_add_site.current.id }}'
site: '{{ msc_site | default("ansible_test") }}_2'
site: '{{ mso_site | default("ansible_test") }}_2'
register: nm_change_site_again
- name: Verify nm_change_site_again
@ -160,25 +160,25 @@
that:
- nm_change_site_again is not changed
- nm_change_site_again.current.id == nm_add_site.current.id
- nm_change_site_again.current.name == '{{ msc_site | default("ansible_test") }}_2'
- nm_change_site_again.current.name == '{{ mso_site | default("ansible_test") }}_2'
# QUERY ALL SITES
- name: Query all sites (check_mode)
msc_site: &site_query
host: '{{ msc_hostname }}'
username: '{{ msc_username }}'
password: '{{ msc_password }}'
validate_certs: '{{ msc_validate_certs | default(false) }}'
use_ssl: '{{ msc_use_ssl | default(true) }}'
use_proxy: '{{ msc_use_proxy | default(true) }}'
output_level: '{{ msc_output_level | default("info") }}'
mso_site: &site_query
host: '{{ mso_hostname }}'
username: '{{ mso_username }}'
password: '{{ mso_password }}'
validate_certs: '{{ mso_validate_certs | default(false) }}'
use_ssl: '{{ mso_use_ssl | default(true) }}'
use_proxy: '{{ mso_use_proxy | default(true) }}'
output_level: '{{ mso_output_level | default("info") }}'
state: query
check_mode: yes
register: cm_query_all_sites
- name: Query all sites (normal mode)
msc_site: *site_query
mso_site: *site_query
register: nm_query_all_sites
- name: Verify query_all_sites
@ -192,16 +192,16 @@
# QUERY A SITE
- name: Query our site
msc_site:
mso_site:
<<: *site_query
site: '{{ msc_site | default("ansible_test") }}_2'
site: '{{ mso_site | default("ansible_test") }}_2'
check_mode: yes
register: cm_query_site
- name: Query our site
msc_site:
mso_site:
<<: *site_query
site: '{{ msc_site | default("ansible_test") }}_2'
site: '{{ mso_site | default("ansible_test") }}_2'
register: nm_query_site
- name: Verify query_site
@ -209,16 +209,16 @@
that:
- cm_query_site is not changed
- cm_query_site.current.id == nm_add_site.current.id
- cm_query_site.current.name == '{{ msc_site | default("ansible_test") }}_2'
- cm_query_site.current.name == '{{ mso_site | default("ansible_test") }}_2'
- nm_query_site is not changed
- nm_query_site.current.id == nm_add_site.current.id
- nm_query_site.current.name == '{{ msc_site | default("ansible_test") }}_2'
- nm_query_site.current.name == '{{ mso_site | default("ansible_test") }}_2'
- cm_query_site == nm_query_site
# REMOVE SITE
- name: Remove site (check_mode)
msc_site: *site_absent
mso_site: *site_absent
check_mode: yes
register: cm_remove_site
@ -229,7 +229,7 @@
- cm_remove_site.current == {}
- name: Remove site (normal mode)
msc_site: *site_absent
mso_site: *site_absent
register: nm_remove_site
- name: Verify nm_remove_site
@ -239,7 +239,7 @@
- nm_remove_site.current == {}
- name: Remove site again (check_mode)
msc_site: *site_absent
mso_site: *site_absent
check_mode: yes
register: cm_remove_site_again
@ -250,7 +250,7 @@
- cm_remove_site_again.current == {}
- name: Remove site again (normal mode)
msc_site: *site_absent
mso_site: *site_absent
register: nm_remove_site_again
- name: Verify nm_remove_site_again
@ -262,16 +262,16 @@
# QUERY NON-EXISTING SITE
- name: Query non-existing site (check_mode)
msc_site:
mso_site:
<<: *site_query
site: '{{ msc_site | default("ansible_test") }}'
site: '{{ mso_site | default("ansible_test") }}'
check_mode: yes
register: cm_query_non_site
- name: Query non-existing site (normal mode)
msc_site:
mso_site:
<<: *site_query
site: '{{ msc_site | default("ansible_test") }}'
site: '{{ mso_site | default("ansible_test") }}'
register: nm_query_non_site
# TODO: Implement more tests

@ -1,29 +1,29 @@
# Test code for the MSC modules
# Test code for the MSO modules
# Copyright: (c) 2018, Dag Wieers (@dagwieers) <dag@wieers.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
- name: Test that we have an ACI MultiSite host, username and password
fail:
msg: 'Please define the following variables: msc_hostname, msc_username and msc_password.'
when: msc_hostname is not defined or msc_username is not defined or msc_password is not defined
msg: 'Please define the following variables: mso_hostname, mso_username and mso_password.'
when: mso_hostname is not defined or mso_username is not defined or mso_password is not defined
# CLEAN ENVIRONMENT
- name: Remove tenant ansible_test2
msc_tenant: &tenant_absent
host: '{{ msc_hostname }}'
username: '{{ msc_username }}'
password: '{{ msc_password }}'
validate_certs: '{{ msc_validate_certs | default(false) }}'
use_ssl: '{{ msc_use_ssl | default(true) }}'
use_proxy: '{{ msc_use_proxy | default(true) }}'
output_level: '{{ msc_output_level | default("info") }}'
mso_tenant: &tenant_absent
host: '{{ mso_hostname }}'
username: '{{ mso_username }}'
password: '{{ mso_password }}'
validate_certs: '{{ mso_validate_certs | default(false) }}'
use_ssl: '{{ mso_use_ssl | default(true) }}'
use_proxy: '{{ mso_use_proxy | default(true) }}'
output_level: '{{ mso_output_level | default("info") }}'
tenant: ansible_test2
state: absent
- name: Remove tenant ansible_test
msc_tenant:
mso_tenant:
<<: *tenant_absent
tenant: ansible_test
register: cm_remove_tenant
@ -31,14 +31,14 @@
# ADD TENANT
- name: Add tenant (check_mode)
msc_tenant: &tenant_present
host: '{{ msc_hostname }}'
username: '{{ msc_username }}'
password: '{{ msc_password }}'
validate_certs: '{{ msc_validate_certs | default(false) }}'
use_ssl: '{{ msc_use_ssl | default(true) }}'
use_proxy: '{{ msc_use_proxy | default(true) }}'
output_level: '{{ msc_output_level | default("info") }}'
mso_tenant: &tenant_present
host: '{{ mso_hostname }}'
username: '{{ mso_username }}'
password: '{{ mso_password }}'
validate_certs: '{{ mso_validate_certs | default(false) }}'
use_ssl: '{{ mso_use_ssl | default(true) }}'
use_proxy: '{{ mso_use_proxy | default(true) }}'
output_level: '{{ mso_output_level | default("info") }}'
tenant: ansible_test
display_name: Ansible test title
description: Ansible test tenant
@ -56,7 +56,7 @@
- cm_add_tenant.current.description == 'Ansible test tenant'
- name: Add tenant (normal mode)
msc_tenant: *tenant_present
mso_tenant: *tenant_present
register: nm_add_tenant
- name: nm_Verify add_tenant
@ -69,7 +69,7 @@
- nm_add_tenant.current.description == 'Ansible test tenant'
- name: Add tenant again (check_mode)
msc_tenant: *tenant_present
mso_tenant: *tenant_present
check_mode: yes
register: cm_add_tenant_again
@ -84,7 +84,7 @@
- cm_add_tenant_again.current.description == 'Ansible test tenant'
- name: Add tenant again (normal mode)
msc_tenant: *tenant_present
mso_tenant: *tenant_present
register: nm_add_tenant_again
- name: Verify nm_add_tenant_again
@ -100,7 +100,7 @@
# CHANGE TENANT
- name: Change tenant (check_mode)
msc_tenant:
mso_tenant:
<<: *tenant_present
tenant_id: '{{ nm_add_tenant.current.id }}'
tenant: ansible_test2
@ -117,7 +117,7 @@
- cm_change_tenant.current.description == 'Ansible test tenant 2'
- name: Change tenant (normal mode)
msc_tenant:
mso_tenant:
<<: *tenant_present
tenant_id: '{{ nm_add_tenant.current.id }}'
tenant: ansible_test2
@ -134,7 +134,7 @@
- nm_change_tenant.current.description == 'Ansible test tenant 2'
- name: Change tenant again (check_mode)
msc_tenant:
mso_tenant:
<<: *tenant_present
tenant_id: '{{ nm_add_tenant.current.id }}'
tenant: ansible_test2
@ -151,7 +151,7 @@
- cm_change_tenant_again.current.description == 'Ansible test tenant 2'
- name: Change tenant again (normal mode)
msc_tenant:
mso_tenant:
<<: *tenant_present
tenant_id: '{{ nm_add_tenant.current.id }}'
tenant: ansible_test2
@ -169,20 +169,20 @@
# QUERY ALL TENANTS
- name: Query all tenants (check_mode)
msc_tenant: &tenant_query
host: '{{ msc_hostname }}'
username: '{{ msc_username }}'
password: '{{ msc_password }}'
validate_certs: '{{ msc_validate_certs | default(false) }}'
use_ssl: '{{ msc_use_ssl | default(true) }}'
use_proxy: '{{ msc_use_proxy | default(true) }}'
output_level: '{{ msc_output_level | default("info") }}'
mso_tenant: &tenant_query
host: '{{ mso_hostname }}'
username: '{{ mso_username }}'
password: '{{ mso_password }}'
validate_certs: '{{ mso_validate_certs | default(false) }}'
use_ssl: '{{ mso_use_ssl | default(true) }}'
use_proxy: '{{ mso_use_proxy | default(true) }}'
output_level: '{{ mso_output_level | default("info") }}'
state: query
check_mode: yes
register: cm_query_all_tenants
- name: Query all tenants (normal mode)
msc_tenant: *tenant_query
mso_tenant: *tenant_query
register: nm_query_all_tenants
- name: Verify query_all_tenants
@ -196,14 +196,14 @@
# QUERY A TENANT
- name: Query our tenant
msc_tenant:
mso_tenant:
<<: *tenant_query
tenant: ansible_test2
check_mode: yes
register: cm_query_tenant
- name: Query our tenant
msc_tenant:
mso_tenant:
<<: *tenant_query
tenant: ansible_test2
register: nm_query_tenant
@ -224,7 +224,7 @@
# REMOVE TENANT
- name: Remove tenant (check_mode)
msc_tenant: *tenant_absent
mso_tenant: *tenant_absent
check_mode: yes
register: cm_remove_tenant
@ -235,7 +235,7 @@
- cm_remove_tenant.current == {}
- name: Remove tenant (normal mode)
msc_tenant: *tenant_absent
mso_tenant: *tenant_absent
register: nm_remove_tenant
- name: Verify nm_remove_tenant
@ -245,7 +245,7 @@
- nm_remove_tenant.current == {}
- name: Remove tenant again (check_mode)
msc_tenant: *tenant_absent
mso_tenant: *tenant_absent
check_mode: yes
register: cm_remove_tenant_again
@ -256,7 +256,7 @@
- cm_remove_tenant_again.current == {}
- name: Remove tenant again (normal mode)
msc_tenant: *tenant_absent
mso_tenant: *tenant_absent
register: nm_remove_tenant_again
- name: Verify nm_remove_tenant_again
@ -268,14 +268,14 @@
# QUERY NON-EXISTING TENANT
- name: Query non-existing tenant (check_mode)
msc_tenant:
mso_tenant:
<<: *tenant_query
tenant: ansible_test
check_mode: yes
register: cm_query_non_tenant
- name: Query non-existing tenant (normal mode)
msc_tenant:
mso_tenant:
<<: *tenant_query
tenant: ansible_test
register: nm_query_non_tenant

@ -1,29 +1,29 @@
# Test code for the MSC modules
# Test code for the MSO modules
# Copyright: (c) 2018, Dag Wieers (@dagwieers) <dag@wieers.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
- name: Test that we have an ACI MultiSite host, username and password
fail:
msg: 'Please define the following variables: msc_hostname, msc_username and msc_password.'
when: msc_hostname is not defined or msc_username is not defined or msc_password is not defined
msg: 'Please define the following variables: mso_hostname, mso_username and mso_password.'
when: mso_hostname is not defined or mso_username is not defined or mso_password is not defined
# CLEAN ENVIRONMENT
- name: Remove user ansible_test2
msc_user: &user_absent
host: '{{ msc_hostname }}'
username: '{{ msc_username }}'
password: '{{ msc_password }}'
validate_certs: '{{ msc_validate_certs | default(false) }}'
use_ssl: '{{ msc_use_ssl | default(true) }}'
use_proxy: '{{ msc_use_proxy | default(true) }}'
output_level: '{{ msc_output_level | default("info") }}'
mso_user: &user_absent
host: '{{ mso_hostname }}'
username: '{{ mso_username }}'
password: '{{ mso_password }}'
validate_certs: '{{ mso_validate_certs | default(false) }}'
use_ssl: '{{ mso_use_ssl | default(true) }}'
use_proxy: '{{ mso_use_proxy | default(true) }}'
output_level: '{{ mso_output_level | default("info") }}'
user_name: ansible_test2
state: absent
- name: Remove user ansible_test
msc_user:
mso_user:
<<: *user_absent
user_name: ansible_test
register: cm_remove_user
@ -31,14 +31,14 @@
# ADD USER
- name: Add user (check_mode)
msc_user: &user_present
host: '{{ msc_hostname }}'
username: '{{ msc_username }}'
password: '{{ msc_password }}'
validate_certs: '{{ msc_validate_certs | default(false) }}'
use_ssl: '{{ msc_use_ssl | default(true) }}'
use_proxy: '{{ msc_use_proxy | default(true) }}'
output_level: '{{ msc_output_level | default("info") }}'
mso_user: &user_present
host: '{{ mso_hostname }}'
username: '{{ mso_username }}'
password: '{{ mso_password }}'
validate_certs: '{{ mso_validate_certs | default(false) }}'
use_ssl: '{{ mso_use_ssl | default(true) }}'
use_proxy: '{{ mso_use_proxy | default(true) }}'
output_level: '{{ mso_output_level | default("info") }}'
user_name: ansible_test
user_password: 'S0m3!1n1t14l!p455w0rd'
# NOTE: First name, last name, phone and email are mandatory on creation
@ -64,7 +64,7 @@
- cm_add_user.current.username == 'ansible_test'
- name: Add user (normal mode)
msc_user: *user_present
mso_user: *user_present
register: nm_add_user
- name: nm_Verify add_user
@ -76,7 +76,7 @@
- nm_add_user.current.username == 'ansible_test'
- name: Add user again (check_mode)
msc_user:
mso_user:
<<: *user_present
# NOTE: We need to modify the password for a new user
user_password: 'S0m3!n3w!p455w0rd'
@ -92,7 +92,7 @@
- cm_add_user_again.current.username == 'ansible_test'
- name: Add user again (normal mode)
msc_user:
mso_user:
<<: *user_present
# NOTE: We need to modify the password for a new user
user_password: 'S0m3!n3w!p455w0rd'
@ -109,7 +109,7 @@
# CHANGE USER
- name: Change user (check_mode)
msc_user:
mso_user:
<<: *user_present
user_id: '{{ nm_add_user.current.id }}'
user_name: ansible_test2
@ -125,7 +125,7 @@
- cm_change_user.current.username == 'ansible_test2'
- name: Change user (normal mode)
msc_user:
mso_user:
<<: *user_present
user_id: '{{ nm_add_user.current.id }}'
user_name: ansible_test2
@ -141,7 +141,7 @@
- nm_change_user.current.username == 'ansible_test2'
- name: Change user again (check_mode)
msc_user:
mso_user:
<<: *user_present
user_id: '{{ nm_add_user.current.id }}'
user_name: ansible_test2
@ -157,7 +157,7 @@
- cm_change_user_again.current.username == 'ansible_test2'
- name: Change user again (normal mode)
msc_user:
mso_user:
<<: *user_present
user_id: '{{ nm_add_user.current.id }}'
user_name: ansible_test2
@ -174,20 +174,20 @@
# QUERY ALL USERS
- name: Query all users (check_mode)
msc_user: &user_query
host: '{{ msc_hostname }}'
username: '{{ msc_username }}'
password: '{{ msc_password }}'
validate_certs: '{{ msc_validate_certs | default(false) }}'
use_ssl: '{{ msc_use_ssl | default(true) }}'
use_proxy: '{{ msc_use_proxy | default(true) }}'
output_level: '{{ msc_output_level | default("info") }}'
mso_user: &user_query
host: '{{ mso_hostname }}'
username: '{{ mso_username }}'
password: '{{ mso_password }}'
validate_certs: '{{ mso_validate_certs | default(false) }}'
use_ssl: '{{ mso_use_ssl | default(true) }}'
use_proxy: '{{ mso_use_proxy | default(true) }}'
output_level: '{{ mso_output_level | default("info") }}'
state: query
check_mode: yes
register: cm_query_all_users
- name: Query all users (normal mode)
msc_user: *user_query
mso_user: *user_query
register: nm_query_all_users
- name: Verify query_all_users
@ -201,14 +201,14 @@
# QUERY A USER
- name: Query our user
msc_user:
mso_user:
<<: *user_query
user_name: ansible_test2
check_mode: yes
register: cm_query_user
- name: Query our user
msc_user:
mso_user:
<<: *user_query
user_name: ansible_test2
register: nm_query_user
@ -227,7 +227,7 @@
# REMOVE USER
- name: Remove user (check_mode)
msc_user: *user_absent
mso_user: *user_absent
check_mode: yes
register: cm_remove_user
@ -238,7 +238,7 @@
- cm_remove_user.current == {}
- name: Remove user (normal mode)
msc_user: *user_absent
mso_user: *user_absent
register: nm_remove_user
- name: Verify nm_remove_user
@ -248,7 +248,7 @@
- nm_remove_user.current == {}
- name: Remove user again (check_mode)
msc_user: *user_absent
mso_user: *user_absent
check_mode: yes
register: cm_remove_user_again
@ -259,7 +259,7 @@
- cm_remove_user_again.current == {}
- name: Remove user again (normal mode)
msc_user: *user_absent
mso_user: *user_absent
register: nm_remove_user_again
- name: Verify nm_remove_user_again
@ -271,14 +271,14 @@
# QUERY NON-EXISTING USER
- name: Query non-existing user (check_mode)
msc_user:
mso_user:
<<: *user_query
user_name: ansible_test
check_mode: yes
register: cm_query_non_user
- name: Query non-existing user (normal mode)
msc_user:
mso_user:
<<: *user_query
user_name: ansible_test
register: nm_query_non_user
Loading…
Cancel
Save