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
f3cbcecf
Commit
f3cbcecf
authored
Nov 08, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1563 from lllama/devel
Add an "executable" option to the command and shell modules
parents
a31ca213
e0f0e8c0
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
2 deletions
+23
-2
library/command
+17
-2
library/shell
+6
-0
No files found.
library/command
View file @
f3cbcecf
...
...
@@ -60,6 +60,12 @@ options:
version_added: "0.6"
required: false
default: null
executable:
description:
- change the shell used to execute the command. Should be an absolute path to the executable.
required: false
default: null
version_added: "0.9"
examples:
- code: "command: /sbin/shutdown -t now"
description: "Example from Ansible Playbooks"
...
...
@@ -81,6 +87,7 @@ def main():
shell
=
module
.
params
[
'shell'
]
chdir
=
module
.
params
[
'chdir'
]
executable
=
module
.
params
[
'executable'
]
args
=
module
.
params
[
'args'
]
if
args
.
strip
()
==
''
:
...
...
@@ -94,7 +101,7 @@ def main():
startd
=
datetime
.
datetime
.
now
()
try
:
cmd
=
subprocess
.
Popen
(
args
,
shell
=
shell
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
cmd
=
subprocess
.
Popen
(
args
,
executable
=
executable
,
shell
=
shell
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
out
,
err
=
cmd
.
communicate
()
except
(
OSError
,
IOError
),
e
:
module
.
fail_json
(
rc
=
e
.
errno
,
msg
=
str
(
e
),
cmd
=
args
)
...
...
@@ -140,11 +147,12 @@ class CommandModule(AnsibleModule):
params
=
{}
params
[
'chdir'
]
=
None
params
[
'shell'
]
=
False
params
[
'executable'
]
=
None
if
args
.
find
(
"#USE_SHELL"
)
!=
-
1
:
args
=
args
.
replace
(
"#USE_SHELL"
,
""
)
params
[
'shell'
]
=
True
r
=
re
.
compile
(
r'(^|\s)(creates|removes|chdir)=(?P<quote>[\'"])?(.*?)(?(quote)(?<!\\)(?P=quote))((?<!\\)(?=\s)|$)'
)
r
=
re
.
compile
(
r'(^|\s)(creates|removes|chdir
|executable
)=(?P<quote>[\'"])?(.*?)(?(quote)(?<!\\)(?P=quote))((?<!\\)(?=\s)|$)'
)
for
m
in
r
.
finditer
(
args
):
v
=
m
.
group
(
4
)
.
replace
(
"
\\
"
,
""
)
if
m
.
group
(
2
)
==
"creates"
:
...
...
@@ -182,6 +190,13 @@ class CommandModule(AnsibleModule):
elif
v
[
0
]
!=
'/'
:
self
.
fail_json
(
rc
=
259
,
msg
=
"the path for 'chdir' argument must be fully qualified"
)
params
[
'chdir'
]
=
v
elif
m
.
group
(
2
)
==
"executable"
:
v
=
os
.
path
.
expanduser
(
v
)
if
not
(
os
.
path
.
exists
(
v
)):
self
.
fail_json
(
rc
=
258
,
msg
=
"cannot use executable '
%
s': file does not exist"
%
v
)
elif
v
[
0
]
!=
'/'
:
self
.
fail_json
(
rc
=
259
,
msg
=
"the path for 'executable' argument must be fully qualified"
)
params
[
'executable'
]
=
v
args
=
r
.
sub
(
""
,
args
)
params
[
'args'
]
=
args
return
(
params
,
params
[
'args'
])
...
...
library/shell
View file @
f3cbcecf
...
...
@@ -27,6 +27,12 @@ options:
- cd into this directory before running the command (0.6 and later)
required: false
default: null
executable:
description:
- change the shell used to execute the command. Should be an absolute path to the executable.
required: false
default: null
version_added: "0.9"
examples:
- code: "shell: somescript.sh >> somelog.txt"
description: Execute the command in remote shell
...
...
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