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
4d623d03
Commit
4d623d03
authored
May 03, 2012
by
Jim Richardson
Committed by
Michael DeHaan
May 06, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sudo -u works now. Needs testing and maybe a bit of cleanup
parent
98dda72b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
8 deletions
+10
-8
lib/ansible/connection.py
+6
-4
lib/ansible/runner.py
+4
-4
No files found.
lib/ansible/connection.py
View file @
4d623d03
...
...
@@ -44,10 +44,10 @@ class Connection(object):
_LOCALHOSTRE
=
re
.
compile
(
r"^(127.0.0.1|localhost|
%
s)$"
%
os
.
uname
()[
1
])
def
__init__
(
self
,
runner
,
transport
):
def
__init__
(
self
,
runner
,
transport
,
sudo_user
):
self
.
runner
=
runner
self
.
transport
=
transport
self
.
sudo_user
=
sudo_user
def
connect
(
self
,
host
,
port
=
None
):
conn
=
None
if
self
.
transport
==
'local'
and
self
.
_LOCALHOSTRE
.
search
(
host
):
...
...
@@ -126,7 +126,8 @@ class ParamikoConnection(object):
self
.
ssh
=
self
.
_get_conn
()
return
self
def
exec_command
(
self
,
cmd
,
tmp_path
,
sudoable
=
False
):
def
exec_command
(
self
,
cmd
,
tmp_path
,
sudo_user
,
sudoable
=
False
):
''' run a command on the remote host '''
bufsize
=
4096
chan
=
self
.
ssh
.
get_transport
()
.
open_session
()
...
...
@@ -146,7 +147,8 @@ class ParamikoConnection(object):
# the -p option.
randbits
=
''
.
join
(
chr
(
random
.
randint
(
ord
(
'a'
),
ord
(
'z'
)))
for
x
in
xrange
(
32
))
prompt
=
'[sudo via ansible, key=
%
s] password: '
%
randbits
sudocmd
=
'sudo -k -p "
%
s" -- "$SHELL" -c
%
s'
%
(
prompt
,
pipes
.
quote
(
cmd
))
sudocmd
=
'sudo -k -p "
%
s" -u
%
s -- "$SHELL" -c
%
s'
%
(
prompt
,
sudo_user
,
pipes
.
quote
(
cmd
))
sudo_output
=
''
try
:
chan
.
exec_command
(
sudocmd
)
...
...
lib/ansible/runner.py
View file @
4d623d03
...
...
@@ -116,8 +116,9 @@ class Runner(object):
self
.
generated_jid
=
str
(
random
.
randint
(
0
,
999999999999
))
self
.
sudo_user
=
sudo_user
self
.
transport
=
transport
self
.
connector
=
ansible
.
connection
.
Connection
(
self
,
self
.
transport
)
self
.
connector
=
ansible
.
connection
.
Connection
(
self
,
self
.
transport
,
self
.
sudo_user
)
if
inventory
is
None
:
self
.
inventory
=
ansible
.
inventory
.
Inventory
(
host_list
)
...
...
@@ -144,7 +145,6 @@ class Runner(object):
self
.
basedir
=
basedir
self
.
sudo
=
sudo
self
.
sudo_pass
=
sudo_pass
self
.
sudo_user
=
sudo_user
self
.
is_playbook
=
is_playbook
euid
=
pwd
.
getpwuid
(
os
.
geteuid
())[
0
]
...
...
@@ -625,8 +625,8 @@ class Runner(object):
def
_exec_command
(
self
,
conn
,
cmd
,
tmp
,
sudoable
=
False
):
''' execute a command string over SSH, return the output '''
stdin
,
stdout
,
stderr
=
conn
.
exec_command
(
cmd
,
tmp
,
sudoable
=
sudoable
)
sudo_user
=
self
.
sudo_user
stdin
,
stdout
,
stderr
=
conn
.
exec_command
(
cmd
,
tmp
,
sudo
_user
,
sudo
able
=
sudoable
)
err
=
None
out
=
None
if
type
(
stderr
)
!=
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