Ansible launcher: be smarter about env quotes

When reading the initial env from files, handled quoted values.
Also, only ignore lines that only start with '#' (which matches
pam_env behavior).

Change-Id: Ie84db4fdb5d70b3da062b48920eb4ca603ebeba7
This commit is contained in:
James E. Blair
2016-06-10 13:50:18 -07:00
parent 28178bf6fc
commit a6bbd4001f

View File

@@ -18,7 +18,6 @@
import datetime
import getpass
import os
import re
import subprocess
import threading
@@ -47,12 +46,16 @@ def get_env():
if os.path.exists(fn):
with open(fn) as f:
for line in f:
line = re.sub('#.*', '', line).strip()
if not line:
continue
if line[0] == '#':
continue
if '=' not in line:
continue
k, v = line.split('=')
k, v = line.strip().split('=')
for q in ["'", '"']:
if v[0] == q:
v = v.strip(q)
env[k] = v
return env