@ -255,6 +255,7 @@ import os
from ansible . module_utils . basic import AnsibleModule , json , env_fallback
from ansible . module_utils . urls import fetch_url
from ansible . module_utils . _text import to_native
from ansible . module_utils . common . dict_transformations import recursive_diff
from ansible . module_utils . network . meraki . meraki import MerakiModule , meraki_argument_spec
@ -337,9 +338,12 @@ def create_admin(meraki, org_id, name, email):
if meraki . params [ ' networks ' ] is not None :
nets = meraki . get_nets ( org_id = org_id )
networks = network_factory ( meraki , meraki . params [ ' networks ' ] , nets )
# meraki.fail_json(msg=str(type(networks)), data=networks)
payload [ ' networks ' ] = networks
if is_admin_existing is None : # Create new admin
if meraki . module . check_mode is True :
meraki . result [ ' data ' ] = payload
meraki . result [ ' changed ' ] = True
meraki . exit_json ( * * meraki . result )
path = meraki . construct_path ( ' create ' , function = ' admin ' , org_id = org_id )
r = meraki . request ( path ,
method = ' POST ' ,
@ -354,6 +358,15 @@ def create_admin(meraki, org_id, name, email):
if not meraki . params [ ' networks ' ] :
payload [ ' networks ' ] = [ ]
if meraki . is_update_required ( is_admin_existing , payload ) is True :
if meraki . module . check_mode is True :
diff = recursive_diff ( is_admin_existing , payload )
is_admin_existing . update ( payload )
meraki . result [ ' diff ' ] = { ' before ' : diff [ 0 ] ,
' after ' : diff [ 1 ] ,
}
meraki . result [ ' changed ' ] = True
meraki . result [ ' data ' ] = payload
meraki . exit_json ( * * meraki . result )
path = meraki . construct_path ( ' update ' , function = ' admin ' , org_id = org_id ) + is_admin_existing [ ' id ' ]
r = meraki . request ( path ,
method = ' PUT ' ,
@ -364,6 +377,9 @@ def create_admin(meraki, org_id, name, email):
return r
else :
meraki . result [ ' data ' ] = is_admin_existing
if meraki . module . check_mode is True :
meraki . result [ ' data ' ] = payload
meraki . exit_json ( * * meraki . result )
return - 1
@ -395,7 +411,7 @@ def main():
# args/params passed to the execution, as well as if the module
# supports check mode
module = AnsibleModule ( argument_spec = argument_spec ,
supports_check_mode = Fals e,
supports_check_mode = Tru e,
)
meraki = MerakiModule ( module , function = ' admin ' )
@ -421,16 +437,11 @@ def main():
except KeyError :
pass
if meraki . params [ ' auth_key ' ] is None :
module . fail_json ( msg = ' Meraki Dashboard API key not set ' )
payload = None
# if the user is working with this module in only check mode we do not
# want to make any changes to the environment, just return the current
# state with no modifications
if module . check_mode :
return result
# execute checks for argument completeness
if meraki . params [ ' state ' ] == ' query ' :
@ -468,6 +479,10 @@ def main():
if r != - 1 :
meraki . result [ ' data ' ] = r
elif meraki . params [ ' state ' ] == ' absent ' :
if meraki . module . check_mode is True :
meraki . result [ ' data ' ] = { }
meraki . result [ ' changed ' ] = True
meraki . exit_json ( * * meraki . result )
admin_id = get_admin_id ( meraki ,
get_admins ( meraki , org_id ) ,
email = meraki . params [ ' email ' ]