@ -674,9 +674,9 @@ class User(object):
cmd . append ( ' -r ' )
cmd . append ( self . name )
( rc , err, out ) = self . execute_command ( cmd )
( rc , out, err ) = self . execute_command ( cmd )
if not self . local or rc != 0 :
return ( rc , err, out )
return ( rc , out, err )
if self . expires is not None :
if self . expires < time . gmtime ( 0 ) :
@ -684,17 +684,17 @@ class User(object):
else :
# Convert seconds since Epoch to days since Epoch
lexpires = int ( math . floor ( self . module . params [ ' expires ' ] ) ) / / 86400
( rc , _ err, _out ) = self . execute_command ( [ lchage_cmd , ' -E ' , to_native ( lexpires ) , self . name ] )
( rc , _ out, _err ) = self . execute_command ( [ lchage_cmd , ' -E ' , to_native ( lexpires ) , self . name ] )
out + = _out
err + = _err
if rc != 0 :
return ( rc , out , err )
if self . groups is None or len ( self . groups ) == 0 :
return ( rc , err, out )
return ( rc , out, err )
for add_group in groups :
( rc , _ err, _out ) = self . execute_command ( [ lgroupmod_cmd , ' -M ' , self . name , add_group ] )
( rc , _ out, _err ) = self . execute_command ( [ lgroupmod_cmd , ' -M ' , self . name , add_group ] )
out + = _out
err + = _err
if rc != 0 :
@ -848,35 +848,35 @@ class User(object):
cmd . append ( ' -p ' )
cmd . append ( self . password )
( rc , err, out ) = ( None , ' ' , ' ' )
( rc , out, err ) = ( None , ' ' , ' ' )
# skip if no usermod changes to be made
if len ( cmd ) > 1 :
cmd . append ( self . name )
( rc , err, out ) = self . execute_command ( cmd )
( rc , out, err ) = self . execute_command ( cmd )
if not self . local or not ( rc is None or rc == 0 ) :
return ( rc , err, out )
return ( rc , out, err )
if lexpires is not None :
( rc , _ err, _out ) = self . execute_command ( [ lchage_cmd , ' -E ' , to_native ( lexpires ) , self . name ] )
( rc , _ out, _err ) = self . execute_command ( [ lchage_cmd , ' -E ' , to_native ( lexpires ) , self . name ] )
out + = _out
err + = _err
if rc != 0 :
return ( rc , out , err )
if len ( lgroupmod_add ) == 0 and len ( lgroupmod_del ) == 0 :
return ( rc , err, out )
return ( rc , out, err )
for add_group in lgroupmod_add :
( rc , _ err, _out ) = self . execute_command ( [ lgroupmod_cmd , ' -M ' , self . name , add_group ] )
( rc , _ out, _err ) = self . execute_command ( [ lgroupmod_cmd , ' -M ' , self . name , add_group ] )
out + = _out
err + = _err
if rc != 0 :
return ( rc , out , err )
for del_group in lgroupmod_del :
( rc , _ err, _out ) = self . execute_command ( [ lgroupmod_cmd , ' -m ' , self . name , del_group ] )
( rc , _ out, _err ) = self . execute_command ( [ lgroupmod_cmd , ' -m ' , self . name , del_group ] )
out + = _out
err + = _err
if rc != 0 :
@ -2239,20 +2239,20 @@ class DarwinUser(User):
if self . append is False :
for remove in current - target :
( _rc , _ err, _out ) = self . __modify_group ( remove , ' delete ' )
( _rc , _ out, _err ) = self . __modify_group ( remove , ' delete ' )
rc + = rc
out + = _out
err + = _err
changed = True
for add in target - current :
( _rc , _ err, _out ) = self . __modify_group ( add , ' add ' )
( _rc , _ out, _err ) = self . __modify_group ( add , ' add ' )
rc + = _rc
out + = _out
err + = _err
changed = True
return ( rc , err, out , changed )
return ( rc , out, err , changed )
def _update_system_user ( self ) :
''' Hide or show user on login window according SELF.SYSTEM.
@ -2323,7 +2323,7 @@ class DarwinUser(User):
def create_user ( self , command_name = ' dscl ' ) :
cmd = self . _get_dscl ( )
cmd + = [ ' -create ' , ' /Users/ %s ' % self . name ]
( rc , err, out ) = self . execute_command ( cmd )
( rc , out, err ) = self . execute_command ( cmd )
if rc != 0 :
self . module . fail_json ( msg = ' Cannot create user " %s " . ' % self . name , err = err , out = out , rc = rc )
@ -2350,16 +2350,16 @@ class DarwinUser(User):
cmd = self . _get_dscl ( )
cmd + = [ ' -create ' , ' /Users/ %s ' % self . name , field [ 1 ] , self . __dict__ [ field [ 0 ] ] ]
( rc , _ err, _out ) = self . execute_command ( cmd )
( rc , _ out, _err ) = self . execute_command ( cmd )
if rc != 0 :
self . module . fail_json ( msg = ' Cannot add property " %s " to user " %s " . ' % ( field [ 0 ] , self . name ) , err = err , out = out , rc = rc )
out + = _out
err + = _err
if rc != 0 :
return ( rc , _ err, _out )
return ( rc , _ out, _err )
( rc , _ err, _out ) = self . _change_user_password ( )
( rc , _ out, _err ) = self . _change_user_password ( )
out + = _out
err + = _err
@ -2370,7 +2370,7 @@ class DarwinUser(User):
( rc , _out , _err , changed ) = self . _modify_group ( )
out + = _out
err + = _err
return ( rc , err, out )
return ( rc , out, err )
def modify_user ( self ) :
changed = None
@ -2386,7 +2386,7 @@ class DarwinUser(User):
if current is None or current != to_text ( self . __dict__ [ field [ 0 ] ] ) :
cmd = self . _get_dscl ( )
cmd + = [ ' -create ' , ' /Users/ %s ' % self . name , field [ 1 ] , self . __dict__ [ field [ 0 ] ] ]
( rc , _ err, _out ) = self . execute_command ( cmd )
( rc , _ out, _err ) = self . execute_command ( cmd )
if rc != 0 :
self . module . fail_json (
msg = ' Cannot update property " %s " for user " %s " . '
@ -2395,7 +2395,7 @@ class DarwinUser(User):
out + = _out
err + = _err
if self . update_password == ' always ' and self . password is not None :
( rc , _ err, _out ) = self . _change_user_password ( )
( rc , _ out, _err ) = self . _change_user_password ( )
out + = _out
err + = _err
changed = rc