added skeleton support in user module

reviewable/pr18780/r1
louis 10 years ago
parent db5668b84c
commit 45f41f4b05

@ -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:
@ -245,6 +249,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']
@ -324,6 +329,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')
@ -593,10 +602,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:
@ -684,6 +697,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)
@ -859,6 +876,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)
@ -1026,6 +1047,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)
@ -1178,6 +1203,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:
@ -1351,6 +1380,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)
@ -1473,6 +1506,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'),

Loading…
Cancel
Save