This commit is contained in:
stefankaerst 2017-06-01 12:21:16 +02:00 committed by Stefan Kaerst
parent 629278464f
commit db1a32f8ca

View file

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