Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKaerst committed Feb 28, 2018
1 parent 6292784 commit db1a32f
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions lib/ansible/modules/system/user.py
Expand Up @@ -182,6 +182,8 @@
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 = '''
Expand Down Expand Up @@ -218,6 +220,12 @@
shell: /bin/zsh
groups: developers
expires: 1422403387
# modify user, remove expiry time
- user:
name: james18
expires: -1
'''

import grp
Expand Down Expand Up @@ -289,13 +297,18 @@ def __init__(self, module):
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']

if module.params['groups'] is not None:
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:
Expand Down Expand Up @@ -517,8 +530,14 @@ def modify_user_usermod(self):
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')
Expand Down

0 comments on commit db1a32f

Please sign in to comment.