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
6250b64e
Commit
6250b64e
authored
Feb 28, 2013
by
Josh Mandel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use relative creates/removes path with chdir
parent
b5ad1ce7
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
27 deletions
+37
-27
library/command
+37
-27
No files found.
library/command
View file @
6250b64e
...
@@ -88,6 +88,8 @@ def main():
...
@@ -88,6 +88,8 @@ def main():
chdir
=
module
.
params
[
'chdir'
]
chdir
=
module
.
params
[
'chdir'
]
executable
=
module
.
params
[
'executable'
]
executable
=
module
.
params
[
'executable'
]
args
=
module
.
params
[
'args'
]
args
=
module
.
params
[
'args'
]
creates
=
module
.
params
[
'creates'
]
removes
=
module
.
params
[
'removes'
]
if
args
.
strip
()
==
''
:
if
args
.
strip
()
==
''
:
module
.
fail_json
(
rc
=
256
,
msg
=
"no command given"
)
module
.
fail_json
(
rc
=
256
,
msg
=
"no command given"
)
...
@@ -95,6 +97,36 @@ def main():
...
@@ -95,6 +97,36 @@ def main():
if
chdir
:
if
chdir
:
os
.
chdir
(
os
.
path
.
expanduser
(
chdir
))
os
.
chdir
(
os
.
path
.
expanduser
(
chdir
))
if
creates
:
# do not run the command if the line contains creates=filename
# and the filename already exists. This allows idempotence
# of command executions.
v
=
os
.
path
.
expanduser
(
creates
)
if
os
.
path
.
exists
(
v
):
module
.
exit_json
(
cmd
=
args
,
stdout
=
"skipped, since
%
s exists"
%
v
,
skipped
=
True
,
changed
=
False
,
stderr
=
False
,
rc
=
0
)
if
removes
:
# do not run the command if the line contains removes=filename
# and the filename does not exist. This allows idempotence
# of command executions.
v
=
os
.
path
.
expanduser
(
removes
)
if
not
os
.
path
.
exists
(
v
):
module
.
exit_json
(
cmd
=
args
,
stdout
=
"skipped, since
%
s does not exist"
%
v
,
skipped
=
True
,
changed
=
False
,
stderr
=
False
,
rc
=
0
)
if
not
shell
:
if
not
shell
:
args
=
shlex
.
split
(
args
)
args
=
shlex
.
split
(
args
)
startd
=
datetime
.
datetime
.
now
()
startd
=
datetime
.
datetime
.
now
()
...
@@ -139,6 +171,8 @@ class CommandModule(AnsibleModule):
...
@@ -139,6 +171,8 @@ class CommandModule(AnsibleModule):
args
=
MODULE_ARGS
args
=
MODULE_ARGS
params
=
{}
params
=
{}
params
[
'chdir'
]
=
None
params
[
'chdir'
]
=
None
params
[
'creates'
]
=
None
params
[
'removes'
]
=
None
params
[
'shell'
]
=
False
params
[
'shell'
]
=
False
params
[
'executable'
]
=
None
params
[
'executable'
]
=
None
if
args
.
find
(
"#USE_SHELL"
)
!=
-
1
:
if
args
.
find
(
"#USE_SHELL"
)
!=
-
1
:
...
@@ -149,38 +183,14 @@ class CommandModule(AnsibleModule):
...
@@ -149,38 +183,14 @@ class CommandModule(AnsibleModule):
for
m
in
r
.
finditer
(
args
):
for
m
in
r
.
finditer
(
args
):
v
=
m
.
group
(
4
)
.
replace
(
"
\\
"
,
""
)
v
=
m
.
group
(
4
)
.
replace
(
"
\\
"
,
""
)
if
m
.
group
(
2
)
==
"creates"
:
if
m
.
group
(
2
)
==
"creates"
:
# do not run the command if the line contains creates=filename
params
[
'creates'
]
=
v
# and the filename already exists. This allows idempotence
# of command executions.
v
=
os
.
path
.
expanduser
(
v
)
if
os
.
path
.
exists
(
v
):
self
.
exit_json
(
cmd
=
args
,
stdout
=
"skipped, since
%
s exists"
%
v
,
skipped
=
True
,
changed
=
False
,
stderr
=
False
,
rc
=
0
)
elif
m
.
group
(
2
)
==
"removes"
:
elif
m
.
group
(
2
)
==
"removes"
:
# do not run the command if the line contains removes=filename
params
[
'removes'
]
=
v
# and the filename do not exists. This allows idempotence
# of command executions.
v
=
os
.
path
.
expanduser
(
v
)
if
not
os
.
path
.
exists
(
v
):
self
.
exit_json
(
cmd
=
args
,
stdout
=
"skipped, since
%
s does not exist"
%
v
,
skipped
=
True
,
changed
=
False
,
stderr
=
False
,
rc
=
0
)
elif
m
.
group
(
2
)
==
"chdir"
:
elif
m
.
group
(
2
)
==
"chdir"
:
v
=
os
.
path
.
expanduser
(
v
)
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
(
rc
=
258
,
msg
=
"cannot change to directory '
%
s': path does not exist"
%
v
)
self
.
fail_json
(
rc
=
258
,
msg
=
"cannot change to directory '
%
s': path does not exist"
%
v
)
elif
v
[
0
]
!=
'/'
:
elif
v
[
0
]
!=
os
.
sep
:
self
.
fail_json
(
rc
=
259
,
msg
=
"the path for 'chdir' argument must be fully qualified"
)
self
.
fail_json
(
rc
=
259
,
msg
=
"the path for 'chdir' argument must be fully qualified"
)
params
[
'chdir'
]
=
v
params
[
'chdir'
]
=
v
elif
m
.
group
(
2
)
==
"executable"
:
elif
m
.
group
(
2
)
==
"executable"
:
...
...
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