1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

added skeleton support in user module

This commit is contained in:
louis 2014-09-30 08:16:19 +02:00 committed by Matt Clay
parent 17b5d851f2
commit 9d20a3091e

View file

@ -74,6 +74,10 @@ options:
required: false required: false
description: description:
- Optionally set the user's home directory. - Optionally set the user's home directory.
skeleton:
required: false
description:
- Optionally set a home skeleton directory. Requires createhome option!
password: password:
required: false required: false
description: description:
@ -260,6 +264,7 @@ class User(object):
self.remove = module.params['remove'] self.remove = module.params['remove']
self.createhome = module.params['createhome'] self.createhome = module.params['createhome']
self.move_home = module.params['move_home'] self.move_home = module.params['move_home']
self.skeleton = module.params['skeleton']
self.system = module.params['system'] self.system = module.params['system']
self.login_class = module.params['login_class'] self.login_class = module.params['login_class']
self.append = module.params['append'] self.append = module.params['append']
@ -360,6 +365,10 @@ class User(object):
if self.createhome: if self.createhome:
cmd.append('-m') cmd.append('-m')
if self.skeleton is not None:
cmd.append('-k')
cmd.append(self.skeleton)
else: else:
cmd.append('-M') cmd.append('-M')
@ -635,10 +644,14 @@ class User(object):
def create_homedir(self, path): def create_homedir(self, path):
if not os.path.exists(path): if not os.path.exists(path):
# use /etc/skel if possible if self.skeleton is not None:
if os.path.exists('/etc/skel'): skeleton = self.skeleton
else:
skeleton = '/etc/skel'
if os.path.exists(skeleton):
try: try:
shutil.copytree('/etc/skel', path, symlinks=True) shutil.copytree(skeleton, path, symlinks=True)
except OSError, e: except OSError, e:
self.module.exit_json(failed=True, msg="%s" % e) self.module.exit_json(failed=True, msg="%s" % e)
else: else:
@ -726,6 +739,10 @@ class FreeBsdUser(User):
if self.createhome: if self.createhome:
cmd.append('-m') cmd.append('-m')
if self.skeleton is not None:
cmd.append('-k')
cmd.append(self.skeleton)
if self.shell is not None: if self.shell is not None:
cmd.append('-s') cmd.append('-s')
cmd.append(self.shell) cmd.append(self.shell)
@ -920,6 +937,10 @@ class OpenBSDUser(User):
if self.createhome: if self.createhome:
cmd.append('-m') cmd.append('-m')
if self.skeleton is not None:
cmd.append('-k')
cmd.append(self.skeleton)
cmd.append(self.name) cmd.append(self.name)
return self.execute_command(cmd) return self.execute_command(cmd)
@ -1087,6 +1108,10 @@ class NetBSDUser(User):
if self.createhome: if self.createhome:
cmd.append('-m') cmd.append('-m')
if self.skeleton is not None:
cmd.append('-k')
cmd.append(self.skeleton)
cmd.append(self.name) cmd.append(self.name)
return self.execute_command(cmd) return self.execute_command(cmd)
@ -1239,6 +1264,10 @@ class SunOS(User):
if self.createhome: if self.createhome:
cmd.append('-m') cmd.append('-m')
if self.skeleton is not None:
cmd.append('-k')
cmd.append(self.skeleton)
cmd.append(self.name) cmd.append(self.name)
if self.module.check_mode: if self.module.check_mode:
@ -1747,6 +1776,10 @@ class AIX(User):
if self.createhome: if self.createhome:
cmd.append('-m') cmd.append('-m')
if self.skeleton is not None:
cmd.append('-k')
cmd.append(self.skeleton)
cmd.append(self.name) cmd.append(self.name)
(rc, out, err) = self.execute_command(cmd) (rc, out, err) = self.execute_command(cmd)
@ -2018,6 +2051,7 @@ def main():
remove=dict(default='no', type='bool'), remove=dict(default='no', type='bool'),
# following options are specific to useradd # following options are specific to useradd
createhome=dict(default='yes', type='bool'), createhome=dict(default='yes', type='bool'),
skeleton=dict(default=None, type='str'),
system=dict(default='no', type='bool'), system=dict(default='no', type='bool'),
# following options are specific to usermod # following options are specific to usermod
move_home=dict(default='no', type='bool'), move_home=dict(default='no', type='bool'),