From 687279c7bdc027d7ddcb75e106837a96b63525c4 Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Mon, 18 Feb 2019 06:59:13 -0800 Subject: [PATCH] Set user expires on FreeBSD using UTC. (#52276) --- changelogs/fragments/user-freebsd-expire-utc.yaml | 2 ++ lib/ansible/modules/system/user.py | 5 +++-- test/integration/targets/user/tasks/main.yml | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/user-freebsd-expire-utc.yaml diff --git a/changelogs/fragments/user-freebsd-expire-utc.yaml b/changelogs/fragments/user-freebsd-expire-utc.yaml new file mode 100644 index 0000000000..b623b5ff89 --- /dev/null +++ b/changelogs/fragments/user-freebsd-expire-utc.yaml @@ -0,0 +1,2 @@ +bugfixes: + - user - on FreeBSD set the user expiration time as seconds since the epoch in UTC to avoid timezone issues diff --git a/lib/ansible/modules/system/user.py b/lib/ansible/modules/system/user.py index eb54b80374..753a8e67a0 100644 --- a/lib/ansible/modules/system/user.py +++ b/lib/ansible/modules/system/user.py @@ -404,6 +404,7 @@ uid: import errno import grp +import calendar import os import re import pty @@ -1150,7 +1151,7 @@ class FreeBsdUser(User): if self.expires < time.gmtime(0): cmd.append('0') else: - cmd.append(time.strftime(self.DATE_FORMAT, self.expires)) + cmd.append(str(calendar.timegm(self.expires))) # system cannot be handled currently - should we error if its requested? # create the user @@ -1268,7 +1269,7 @@ class FreeBsdUser(User): # Current expires is negative or we compare year, month, and day only if current_expires <= 0 or current_expire_date[:3] != self.expires[:3]: cmd.append('-e') - cmd.append(time.strftime(self.DATE_FORMAT, self.expires)) + cmd.append(str(calendar.timegm(self.expires))) # modify the user if cmd will do anything if cmd_len != len(cmd): diff --git a/test/integration/targets/user/tasks/main.yml b/test/integration/targets/user/tasks/main.yml index e36cb60951..bc268e2d51 100644 --- a/test/integration/targets/user/tasks/main.yml +++ b/test/integration/targets/user/tasks/main.yml @@ -364,7 +364,7 @@ - name: BSD | Ensure proper expiration date was set assert: that: - - bsd_account_expiration.stdout == '2529878400' + - bsd_account_expiration.stdout == '2529881062' when: ansible_facts.os_family == 'FreeBSD' - name: Change timezone