mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Fixed user.present on existing user
This commit is contained in:
parent
b99484fde2
commit
a208e1d60f
2 changed files with 10 additions and 4 deletions
|
@ -162,15 +162,16 @@ def removegroup(name, group):
|
|||
return ret['retcode'] == 0
|
||||
|
||||
|
||||
def chhome(name, home):
|
||||
def chhome(name, home, persist=False):
|
||||
'''
|
||||
Change the home directory of the user
|
||||
Change the home directory of the user, pass True for persist to move files
|
||||
to the new home directory if the old home directory exist.
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' user.chhome foo \\\\fileserver\\home\\foo
|
||||
salt '*' user.chhome foo \\\\fileserver\\home\\foo True
|
||||
'''
|
||||
pre_info = info(name)
|
||||
|
||||
|
@ -184,6 +185,11 @@ def chhome(name, home):
|
|||
if __salt__['cmd.retcode'](cmd, python_shell=False) != 0:
|
||||
return False
|
||||
|
||||
if persist and home is not None and pre_info['home'] is not None:
|
||||
cmd = 'move /Y {0} {1}'.format(pre_info['home'], home)
|
||||
if __salt__['cmd.retcode'](cmd, python_shell=False) != 0:
|
||||
log.debug('Failed to move the contents of the Home Directory')
|
||||
|
||||
post_info = info(name)
|
||||
if post_info['home'] != pre_info['home']:
|
||||
return post_info['home'] == home
|
||||
|
|
|
@ -109,7 +109,7 @@ def _changes(name,
|
|||
change['home'] = home
|
||||
if createhome:
|
||||
newhome = home if home else lusr['home']
|
||||
if not os.path.isdir(newhome):
|
||||
if newhome is not None and not os.path.isdir(newhome):
|
||||
change['homeDoesNotExist'] = newhome
|
||||
|
||||
if shell:
|
||||
|
|
Loading…
Add table
Reference in a new issue