@ -193,7 +193,7 @@ options:
- Lock the password ( usermod - L , pw lock , usermod - C ) .
- Lock the password ( usermod - L , pw lock , usermod - C ) .
BUT implementation differs on different platforms , this option does not always mean the user cannot login via other methods .
BUT implementation differs on different platforms , this option does not always mean the user cannot login via other methods .
This option does not disable the user , only lock the password . Do not change the password in the same task .
This option does not disable the user , only lock the password . Do not change the password in the same task .
Currently supported on Linux , FreeBSD , DragonFlyBSD , NetBSD .
Currently supported on Linux , FreeBSD , DragonFlyBSD , NetBSD , OpenBSD .
type : bool
type : bool
version_added : " 2.6 "
version_added : " 2.6 "
local :
local :
@ -674,9 +674,11 @@ class User(object):
cmd . append ( ' -e ' )
cmd . append ( ' -e ' )
cmd . append ( time . strftime ( self . DATE_FORMAT , self . expires ) )
cmd . append ( time . strftime ( self . DATE_FORMAT , self . expires ) )
if self . password_lock :
# Lock if no password or unlocked, unlock only if locked
if self . password_lock and not info [ 1 ] . startswith ( ' ! ' ) :
cmd . append ( ' -L ' )
cmd . append ( ' -L ' )
elif self . password_lock is not None :
elif self . password_lock is False and info [ 1 ] . startswith ( ' ! ' ) :
# usermod will refuse to unlock a user with no password, module shows 'changed' regardless
cmd . append ( ' -U ' )
cmd . append ( ' -U ' )
if self . update_password == ' always ' and self . password is not None and info [ 1 ] != self . password :
if self . update_password == ' always ' and self . password is not None and info [ 1 ] != self . password :
@ -1170,22 +1172,20 @@ class FreeBsdUser(User):
return self . execute_command ( cmd )
return self . execute_command ( cmd )
# we have to lock/unlock the password in a distinct command
# we have to lock/unlock the password in a distinct command
if self . password_lock :
if self . password_lock and not info [ 1 ] . startswith ( ' *LOCKED* ' ) :
cmd = [
cmd = [
self . module . get_bin_path ( ' pw ' , True ) ,
self . module . get_bin_path ( ' pw ' , True ) ,
' lock ' ,
' lock ' ,
' -n ' ,
self . name
self . name
]
]
if self . uid is not None and info [ 2 ] != int ( self . uid ) :
if self . uid is not None and info [ 2 ] != int ( self . uid ) :
cmd . append ( ' -u ' )
cmd . append ( ' -u ' )
cmd . append ( self . uid )
cmd . append ( self . uid )
return self . execute_command ( cmd )
return self . execute_command ( cmd )
elif self . password_lock is not None :
elif self . password_lock is False and info [ 1 ] . startswith ( ' *LOCKED* ' ) :
cmd = [
cmd = [
self . module . get_bin_path ( ' pw ' , True ) ,
self . module . get_bin_path ( ' pw ' , True ) ,
' unlock ' ,
' unlock ' ,
' -n ' ,
self . name
self . name
]
]
if self . uid is not None and info [ 2 ] != int ( self . uid ) :
if self . uid is not None and info [ 2 ] != int ( self . uid ) :
@ -1358,6 +1358,11 @@ class OpenBSDUser(User):
cmd . append ( ' -L ' )
cmd . append ( ' -L ' )
cmd . append ( self . login_class )
cmd . append ( self . login_class )
if self . password_lock and not info [ 1 ] . startswith ( ' * ' ) :
cmd . append ( ' -Z ' )
elif self . password_lock is False and info [ 1 ] . startswith ( ' * ' ) :
cmd . append ( ' -U ' )
if self . update_password == ' always ' and self . password is not None \
if self . update_password == ' always ' and self . password is not None \
and self . password != ' * ' and info [ 1 ] != self . password :
and self . password != ' * ' and info [ 1 ] != self . password :
cmd . append ( ' -p ' )
cmd . append ( ' -p ' )
@ -1518,9 +1523,9 @@ class NetBSDUser(User):
cmd . append ( ' -p ' )
cmd . append ( ' -p ' )
cmd . append ( self . password )
cmd . append ( self . password )
if self . password_lock :
if self . password_lock and not info [ 1 ] . startswith ( ' *LOCKED* ' ) :
cmd . append ( ' -C yes ' )
cmd . append ( ' -C yes ' )
elif self . password_lock is not None :
elif self . password_lock is False and info [ 1 ] . startswith ( ' *LOCKED* ' ) :
cmd . append ( ' -C no ' )
cmd . append ( ' -C no ' )
# skip if no changes to be made
# skip if no changes to be made