Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added a 'chdir' argument to the command module #721

Merged
merged 1 commit into from
Jul 30, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions library/command
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ def main():
module = CommandModule(argument_spec=dict())

shell = module.params['shell']
chdir = module.params['chdir']
args = module.params['args']

if chdir:
os.chdir(chdir)

if not shell:
args = shlex.split(args)
startd = datetime.datetime.now()
Expand Down Expand Up @@ -77,6 +81,7 @@ class CommandModule(AnsibleModule):
args = base64.b64decode(MODULE_ARGS)
items = shlex.split(args)
params = {}
params['chdir'] = None
params['shell'] = False
if args.find("#USE_SHELL") != -1:
args = args.replace("#USE_SHELL", "")
Expand All @@ -99,6 +104,14 @@ class CommandModule(AnsibleModule):
rc=0
)
args = args.replace(x,'')
elif x.startswith("chdir="):
(k,v) = x.split("=", 1)
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)
elif v[0] != '/':
self.fail_json(msg="the path for 'chdir' argument must be fully qualified")
params['chdir'] = v
args = args.replace(x, '')
params['args'] = args
return (params, args)

Expand Down