From 766413e79d699c9eff6b61106de3e24b6fbbc151 Mon Sep 17 00:00:00 2001 From: BradLook Date: Wed, 10 Aug 2016 14:30:09 -0700 Subject: [PATCH] Allow cron to target remote user (#4270) --- lib/ansible/modules/system/cron.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/system/cron.py b/lib/ansible/modules/system/cron.py index 949094d0f70..6aca8a7fd04 100644 --- a/lib/ansible/modules/system/cron.py +++ b/lib/ansible/modules/system/cron.py @@ -476,7 +476,7 @@ class CronTab(object): return "%s -l %s" % (pipes.quote(CRONCMD), pipes.quote(self.user)) elif platform.system() == 'HP-UX': return "%s %s %s" % (CRONCMD , '-l', pipes.quote(self.user)) - else: + elif os.getlogin() != self.user: user = '-u %s' % pipes.quote(self.user) return "%s %s %s" % (CRONCMD , user, '-l') @@ -488,7 +488,7 @@ class CronTab(object): if self.user: if platform.system() in ['SunOS', 'HP-UX', 'AIX']: return "chown %s %s ; su '%s' -c '%s %s'" % (pipes.quote(self.user), pipes.quote(path), pipes.quote(self.user), CRONCMD, pipes.quote(path)) - else: + elif os.getlogin() != self.user: user = '-u %s' % pipes.quote(self.user) return "%s %s %s" % (CRONCMD , user, pipes.quote(path))