Added support for passing org_id instead of org_name (#41518)

- Faster execution if passed instead of org_name
- Updated documentation
- Added additional integration tests
pull/41631/merge
Kevin Breit 7 years ago committed by Dag Wieers
parent 5ee0c0af18
commit 4a0b8f5123

@ -69,24 +69,37 @@ EXAMPLES = r'''
- name: Query information about all administrators associated to the organization
meraki_admin:
auth_key: abc12345
org_name: YourOrg
state: query
delegate_to: localhost
- name: Query information about a single administrator by name
meraki_admin:
auth_key: abc12345
org_id: 12345
state: query
name: Jane Doe
- name: Query information about a single administrator by email
meraki_admin:
auth_key: abc12345
org_name: YourOrg
state: query
email: jane@doe.com
- name: new administrator with organization access
- name: Create new administrator with organization access
meraki_admin:
auth_key: abc12345
org_name: YourOrg
state: present
name: Jane Doe
orgAccess: read-only
email: jane@doe.com
- name: Create new administrator with organization access
meraki_admin:
auth_key: abc12345
org_name: YourOrg
state: present
name: Jane Doe
orgAccess: read-only
@ -95,6 +108,7 @@ EXAMPLES = r'''
- name: Create a new administrator with organization access
meraki_admin:
auth_key: abc12345
org_name: YourOrg
state: present
name: Jane Doe
orgAccess: read-only
@ -103,6 +117,7 @@ EXAMPLES = r'''
- name: Revoke access to an organization for an administrator
meraki_admin:
auth_key: abc12345
org_name: YourOrg
state: absent
email: jane@doe.com
'''
@ -144,12 +159,11 @@ def get_admins(meraki, org_id):
return admins
def get_admin_id(meraki, org_name, data, name=None, email=None):
def get_admin_id(meraki, data, name=None, email=None):
admin_id = None
for a in data:
if meraki.params['name'] is not None:
if meraki.params['name'] == a['name']:
# meraki.fail_json(msg='HERE')
if admin_id is not None:
meraki.fail_json(msg='There are multiple administrators with the same name')
else:
@ -319,18 +333,20 @@ def main():
# manipulate or modify the state as needed (this is going to be the
# part where your module will do what it needs to do)
org_id = meraki.params['org_id']
if not meraki.params['org_id']:
org_id = meraki.get_org_id(meraki.params['org_name'])
if meraki.params['state'] == 'query':
admins = get_admins(meraki, org_id)
if not meraki.params['name'] and not meraki.params['email']: # Return all admins for org
meraki.result['data'] = admins
if meraki.params['name'] is not None: # Return a single admin for org
admin_id = get_admin_id(meraki, meraki.params['org_name'], admins, name=meraki.params['name'])
admin_id = get_admin_id(meraki, admins, name=meraki.params['name'])
meraki.result['data'] = admin_id
admin = get_admin(meraki, admins, admin_id)
meraki.result['data'] = admin
elif meraki.params['email'] is not None:
admin_id = get_admin_id(meraki, meraki.params['org_name'], admins, email=meraki.params['email'])
admin_id = get_admin_id(meraki, admins, email=meraki.params['email'])
meraki.result['data'] = admin_id
admin = get_admin(meraki, admins, admin_id)
meraki.result['data'] = admin
@ -344,7 +360,6 @@ def main():
meraki.result['data'] = r
elif meraki.params['state'] == 'absent':
admin_id = get_admin_id(meraki,
meraki.params['org_name'],
get_admins(meraki, org_id),
email=meraki.params['email']
)

@ -20,6 +20,32 @@
- create_orgaccess.changed == true
- 'create_orgaccess.data.name == "Jane Doe"'
- name: Delete recently created administrator
meraki_admin:
auth_key: '{{auth_key}}'
state: absent
org_name: '{{test_org_name}}'
email: '{{email_prefix}}+janedoe@{{email_domain}}'
delegate_to: localhost
register: delete_one
- name: Create new administrator with org_id
meraki_admin:
auth_key: '{{auth_key}}'
state: present
org_id: '{{test_org_id}}'
name: Jane Doe
email: '{{email_prefix}}+janedoe@{{email_domain}}'
orgAccess: read-only
delegate_to: localhost
register: create_orgaccess_id
- name: Create new admin assertion
assert:
that:
- create_orgaccess_id.changed == true
- 'create_orgaccess_id.data.name == "Jane Doe"'
- name: Create administrator with tags
meraki_admin:
auth_key: '{{auth_key}}'

Loading…
Cancel
Save