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
5231be5d
Commit
5231be5d
authored
Jan 10, 2013
by
Daniel Hokka Zakrisson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add sudo password support for local
parent
7ecab223
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
6 deletions
+29
-6
lib/ansible/runner/connection_plugins/local.py
+29
-6
No files found.
lib/ansible/runner/connection_plugins/local.py
View file @
5231be5d
...
...
@@ -20,6 +20,8 @@ import os
import
pipes
import
shutil
import
subprocess
import
select
import
fcntl
from
ansible
import
errors
from
ansible
import
utils
from
ansible.callbacks
import
vvv
...
...
@@ -44,17 +46,38 @@ class Connection(object):
if
not
self
.
runner
.
sudo
or
not
sudoable
:
local_cmd
=
[
executable
,
'-c'
,
cmd
]
else
:
if
self
.
runner
.
sudo_pass
:
# NOTE: if someone wants to add sudo w/ password to the local connection type, they are welcome
# to do so. The primary usage of the local connection is for crontab and kickstart usage however
# so this doesn't seem to be a huge priority
raise
errors
.
AnsibleError
(
"sudo with password is presently only supported on the 'paramiko' (SSH) and native 'ssh' connection types"
)
local_cmd
,
prompt
=
utils
.
make_sudo_cmd
(
sudo_user
,
executable
,
cmd
)
vvv
(
"EXEC
%
s"
%
local_cmd
,
host
=
self
.
host
)
vvv
(
"EXEC
%
s"
%
(
local_cmd
)
,
host
=
self
.
host
)
p
=
subprocess
.
Popen
(
local_cmd
,
shell
=
isinstance
(
local_cmd
,
basestring
),
cwd
=
self
.
runner
.
basedir
,
executable
=
executable
,
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
if
self
.
runner
.
sudo
and
sudoable
and
self
.
runner
.
sudo_pass
:
fcntl
.
fcntl
(
p
.
stdout
,
fcntl
.
F_SETFL
,
fcntl
.
fcntl
(
p
.
stdout
,
fcntl
.
F_GETFL
)
|
os
.
O_NONBLOCK
)
fcntl
.
fcntl
(
p
.
stderr
,
fcntl
.
F_SETFL
,
fcntl
.
fcntl
(
p
.
stderr
,
fcntl
.
F_GETFL
)
|
os
.
O_NONBLOCK
)
sudo_output
=
''
while
not
sudo_output
.
endswith
(
prompt
):
rfd
,
wfd
,
efd
=
select
.
select
([
p
.
stdout
,
p
.
stderr
],
[],
[
p
.
stdout
,
p
.
stderr
],
self
.
runner
.
timeout
)
if
p
.
stdout
in
rfd
:
chunk
=
p
.
stdout
.
read
()
elif
p
.
stderr
in
rfd
:
chunk
=
p
.
stderr
.
read
()
else
:
stdout
,
stderr
=
p
.
communicate
()
raise
errors
.
AnsibleError
(
'timeout waiting for sudo password prompt:
\n
'
+
sudo_output
)
if
not
chunk
:
stdout
,
stderr
=
p
.
communicate
()
raise
errors
.
AnsibleError
(
'sudo output closed while waiting for password prompt:
\n
'
+
sudo_output
)
sudo_output
+=
chunk
p
.
stdin
.
write
(
self
.
runner
.
sudo_pass
+
'
\n
'
)
fcntl
.
fcntl
(
p
.
stdout
,
fcntl
.
F_SETFL
,
fcntl
.
fcntl
(
p
.
stdout
,
fcntl
.
F_GETFL
)
&
~
os
.
O_NONBLOCK
)
fcntl
.
fcntl
(
p
.
stderr
,
fcntl
.
F_SETFL
,
fcntl
.
fcntl
(
p
.
stderr
,
fcntl
.
F_GETFL
)
&
~
os
.
O_NONBLOCK
)
stdout
,
stderr
=
p
.
communicate
()
return
(
p
.
returncode
,
''
,
stdout
,
stderr
)
...
...
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