diff --git a/lib/ansible/modules/system/user.py b/lib/ansible/modules/system/user.py index f1b023ab3e32ac..4dbba573fb44ec 100644 --- a/lib/ansible/modules/system/user.py +++ b/lib/ansible/modules/system/user.py @@ -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 = ''' @@ -218,6 +220,12 @@ shell: /bin/zsh groups: developers expires: 1422403387 + +# modify user, remove expiry time +- user: + name: james18 + expires: -1 + ''' import grp @@ -289,6 +297,7 @@ 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'] @@ -296,6 +305,10 @@ def __init__(self, module): 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 @@ 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')