pull/25254/head^2
stefankaerst 8 years ago committed by Stefan Kaerst
parent 629278464f
commit db1a32f8ca

@ -182,6 +182,8 @@ options:
type: bool type: bool
default: 'no' default: 'no'
version_added: "2.4" version_added: "2.4"
- To remove the expiry time specify a negative value.
Currently supported on GNU/Linux and FreeBSD.
''' '''
EXAMPLES = ''' EXAMPLES = '''
@ -218,6 +220,12 @@ EXAMPLES = '''
shell: /bin/zsh shell: /bin/zsh
groups: developers groups: developers
expires: 1422403387 expires: 1422403387
# modify user, remove expiry time
- user:
name: james18
expires: -1
''' '''
import grp import grp
@ -289,6 +297,7 @@ class User(object):
self.update_password = module.params['update_password'] self.update_password = module.params['update_password']
self.home = module.params['home'] self.home = module.params['home']
self.expires = None self.expires = None
self.clearexpires = None
self.groups = None self.groups = None
self.local = module.params['local'] self.local = module.params['local']
@ -296,6 +305,10 @@ class User(object):
self.groups = ','.join(module.params['groups']) self.groups = ','.join(module.params['groups'])
if module.params['expires']: if module.params['expires']:
try:
self.clearexpires = float(module.params['expires'])
except:
pass
try: try:
self.expires = time.gmtime(module.params['expires']) self.expires = time.gmtime(module.params['expires'])
except Exception as e: except Exception as e:
@ -517,8 +530,14 @@ class User(object):
cmd.append(self.shell) cmd.append(self.shell)
if self.expires: if self.expires:
cmd.append('-e') cmd.append('--expiredate')
try:
if self.clearexpires < 0:
cmd.append('')
else:
cmd.append(time.strftime(self.DATE_FORMAT, self.expires)) cmd.append(time.strftime(self.DATE_FORMAT, self.expires))
except ValueError:
raise
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:
cmd.append('-p') cmd.append('-p')

Loading…
Cancel
Save