Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
38c7f1db
Commit
38c7f1db
authored
Apr 06, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added 'creates=filename' to the shell/command module, which can skip command execution if a file
already exists
parent
7b9856bc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
7 deletions
+28
-7
library/command
+28
-7
No files found.
library/command
View file @
38c7f1db
...
@@ -39,6 +39,26 @@ if args.find("#USE_SHELL") != -1:
...
@@ -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
)
...
@@ -71,13 +91,14 @@ if err is None:
...
@@ -71,13 +91,14 @@ if err is None:
err
=
''
err
=
''
result
=
{
result
=
{
"cmd"
:
args
,
"cmd"
:
args
,
"stdout"
:
out
.
strip
(),
"stdout"
:
out
.
strip
(),
"stderr"
:
err
.
strip
(),
"stderr"
:
err
.
strip
(),
"rc"
:
cmd
.
returncode
,
"rc"
:
cmd
.
returncode
,
"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
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment