Commit 7c2fe3da by Michael DeHaan

Merge pull request #989 from willthames/command-expand-path

Allow ~ expansion in chdir argument of command module
parents 8c028c4c 8b8eae7d
...@@ -39,7 +39,7 @@ def main(): ...@@ -39,7 +39,7 @@ def main():
module.fail_json(msg="no command given") module.fail_json(msg="no command given")
if chdir: if chdir:
os.chdir(chdir) os.chdir(os.path.expanduser(chdir))
if not shell: if not shell:
args = shlex.split(args) args = shlex.split(args)
...@@ -116,6 +116,7 @@ class CommandModule(AnsibleModule): ...@@ -116,6 +116,7 @@ class CommandModule(AnsibleModule):
args = args.replace(x,'') args = args.replace(x,'')
elif x.startswith("chdir="): elif x.startswith("chdir="):
(k,v) = x.split("=", 1) (k,v) = x.split("=", 1)
v = os.path.expanduser(v)
if not (os.path.exists(v) and os.path.isdir(v)): if not (os.path.exists(v) and os.path.isdir(v)):
self.fail_json(msg="cannot change to directory '%s': path does not exist" % v) self.fail_json(msg="cannot change to directory '%s': path does not exist" % v)
elif v[0] != '/': elif v[0] != '/':
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment