Added 'creates=filename' to the shell/command module, which can skip command execution if a file

already exists
reviewable/pr18780/r1
Michael DeHaan 13 years ago
parent c7634619f3
commit 16f3d018c0

@ -39,6 +39,26 @@ if args.find("#USE_SHELL") != -1:
args = args.replace("#USE_SHELL", "") args = args.replace("#USE_SHELL", "")
shell = True shell = True
check_args = shlex.split(args)
for x in check_args:
if x.startswith("creates="):
# do not run the command if the line contains creates=filename
# and the filename already exists. This allows idempotence
# of command executions.
(k,v) = x.split("=",1)
if os.path.exists(v):
print json.dumps({
"cmd" : args,
"stdout" : "skipped, since %s exists" % v,
"skipped" : True,
"changed" : False,
"stderr" : "",
"rc" : 0,
})
sys.exit(0)
args = args.replace(x,'')
if not shell: if not shell:
args = shlex.split(args) args = shlex.split(args)
@ -78,6 +98,7 @@ result = {
"start" : str(startd), "start" : str(startd),
"end" : str(endd), "end" : str(endd),
"delta" : str(delta), "delta" : str(delta),
"changed" : True
} }
print json.dumps(result) print json.dumps(result)

Loading…
Cancel
Save