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
72cc9972
Commit
72cc9972
authored
Mar 28, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sudo tweaks
parent
7ae75eb1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
7 deletions
+24
-7
lib/ansible/connection.py
+23
-6
lib/ansible/runner.py
+1
-1
No files found.
lib/ansible/connection.py
View file @
72cc9972
...
@@ -83,7 +83,7 @@ class ParamikoConnection(object):
...
@@ -83,7 +83,7 @@ class ParamikoConnection(object):
def
exec_command
(
self
,
cmd
,
sudoable
=
True
):
def
exec_command
(
self
,
cmd
,
sudoable
=
True
):
''' run a command on the remote host '''
''' run a command on the remote host '''
if
not
False
:
# if not
self.runner.sudo or not sudoable:
if
not
self
.
runner
.
sudo
or
not
sudoable
:
stdin
,
stdout
,
stderr
=
self
.
ssh
.
exec_command
(
cmd
)
stdin
,
stdout
,
stderr
=
self
.
ssh
.
exec_command
(
cmd
)
return
(
stdin
,
stdout
,
stderr
)
return
(
stdin
,
stdout
,
stderr
)
else
:
else
:
...
@@ -91,15 +91,32 @@ class ParamikoConnection(object):
...
@@ -91,15 +91,32 @@ class ParamikoConnection(object):
self
.
ssh
.
close
()
self
.
ssh
.
close
()
ssh_sudo
=
self
.
_get_conn
()
ssh_sudo
=
self
.
_get_conn
()
sudo_chan
=
ssh_sudo
.
invoke_shell
()
sudo_chan
=
ssh_sudo
.
invoke_shell
()
sudo_chan
.
exec_command
(
"sudo -s
"
)
sudo_chan
.
send
(
"sudo -s
\n
"
)
sudo_chan
.
recv
(
1024
)
sudo_chan
.
recv
(
1024
)
sudo_chan
.
send
(
"
%
s
\n
"
%
cmd
)
sudo_chan
.
send
(
"echo &&
%
s && echo
\n
"
%
cmd
)
# TODO: wait for ready...
while
not
sudo_chan
.
recv_ready
():
# TODO: timeout support
time
.
sleep
(
1
)
out
=
sudo_chan
.
recv
(
1024
)
out
=
sudo_chan
.
recv
(
1024
)
sudo_chan
.
close
()
sudo_chan
.
close
()
self
.
ssh
=
self
.
_get_conn
()
self
.
ssh
=
self
.
_get_conn
()
return
(
None
,
"
\n
"
.
join
(
out
),
''
)
out
=
self
.
_expect_like
(
out
)
return
(
None
,
out
,
''
)
def
_expect_like
(
self
,
msg
):
''' hack to make invoke_shell more or less work for sudo usage '''
lines
=
msg
.
split
(
"
\n
"
)
index
=
0
for
x
in
lines
:
if
x
==
'
\r
'
:
break
index
+=
1
index2
=
index
+
1
for
x
in
lines
[
index
:]:
if
x
==
'
\r
'
:
break
index2
+=
1
return
"
\n
"
.
join
(
lines
[
index
+
1
:
index2
+
1
])
.
strip
()
def
put_file
(
self
,
in_path
,
out_path
):
def
put_file
(
self
,
in_path
,
out_path
):
''' transfer a file from local to remote '''
''' transfer a file from local to remote '''
...
...
lib/ansible/runner.py
View file @
72cc9972
...
@@ -356,7 +356,7 @@ class Runner(object):
...
@@ -356,7 +356,7 @@ class Runner(object):
cmd
=
"
%
s
%
s"
%
(
remote_module_path
,
argsfile
)
cmd
=
"
%
s
%
s"
%
(
remote_module_path
,
argsfile
)
else
:
else
:
cmd
=
" "
.
join
([
str
(
x
)
for
x
in
[
remote_module_path
,
async_jid
,
async_limit
,
async_module
,
argsfile
]])
cmd
=
" "
.
join
([
str
(
x
)
for
x
in
[
remote_module_path
,
async_jid
,
async_limit
,
async_module
,
argsfile
]])
return
[
self
.
_exec_command
(
conn
,
cmd
),
client_executed_str
]
return
[
self
.
_exec_command
(
conn
,
cmd
,
sudoable
=
True
),
client_executed_str
]
# *****************************************************
# *****************************************************
...
...
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