Merge "Ansible launcher: run command in login shell"
diff --git a/zuul/ansible/library/zuul_runner.py b/zuul/ansible/library/zuul_runner.py
index 81d060d..4604f42 100644
--- a/zuul/ansible/library/zuul_runner.py
+++ b/zuul/ansible/library/zuul_runner.py
@@ -16,6 +16,7 @@
 # along with this software.  If not, see <http://www.gnu.org/licenses/>.
 
 import datetime
+import getpass
 import os
 import subprocess
 
@@ -34,13 +35,30 @@
         self.logfile.write(outln)
 
 
+def get_env():
+    env = {}
+    env['HOME'] = os.path.expanduser('~')
+    env['USER'] = getpass.getuser()
+
+    # Known locations for PAM mod_env sources
+    for fn in ['/etc/environment', '/etc/default/locale']:
+        if os.path.exists(fn):
+            with open(fn) as f:
+                for line in f:
+                    k, v = line.strip().split('=')
+                    env[k] = v
+    return env
+
+
 def run(cwd, cmd, args):
+    env = get_env()
+    env.update(args)
     proc = subprocess.Popen(
-        [cmd],
+        ['/bin/bash', '-l', '-c', cmd],
         cwd=cwd,
         stdout=subprocess.PIPE,
         stderr=subprocess.STDOUT,
-        env=args,
+        env=env,
     )
 
     with Console() as console:
@@ -65,7 +83,6 @@
 
     p = module.params
     env = p['parameters'].copy()
-    env['HOME'] = os.path.expanduser('~')
     ret = run(p['cwd'], p['command'], env)
     if ret == 0:
         module.exit_json(changed=True, rc=ret)
diff --git a/zuul/launcher/ansiblelaunchserver.py b/zuul/launcher/ansiblelaunchserver.py
index 14bf5a6..20c5ab8 100644
--- a/zuul/launcher/ansiblelaunchserver.py
+++ b/zuul/launcher/ansiblelaunchserver.py
@@ -746,7 +746,6 @@
 
         parameters = args.copy()
         parameters['WORKSPACE'] = os.path.join(self.workspace_root, job_name)
-        parameters['PATH'] = '/usr/local/bin:/usr/bin:/bin'
 
         with open(jobdir.inventory, 'w') as inventory:
             for host_name, host_vars in self.getHostList():