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
4705409c
Commit
4705409c
authored
Sep 04, 2015
by
Brian Coca
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #12250 from bcoca/become_clean
Become clean
parents
23a22397
c17fbf2f
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
15 additions
and
9 deletions
+15
-9
lib/ansible/playbook/play_context.py
+7
-4
lib/ansible/plugins/connections/local.py
+1
-1
lib/ansible/plugins/connections/paramiko_ssh.py
+0
-1
lib/ansible/plugins/connections/ssh.py
+0
-1
test/units/playbook/test_play_context.py
+7
-2
No files found.
lib/ansible/playbook/play_context.py
View file @
4705409c
...
...
@@ -335,6 +335,7 @@ class PlayContext(Base):
prompt
=
None
success_key
=
None
self
.
prompt
=
None
if
executable
is
None
:
executable
=
C
.
DEFAULT_EXECUTABLE
...
...
@@ -366,13 +367,14 @@ class PlayContext(Base):
# directly doesn't work, so we shellquote it with pipes.quote() and pass the quoted
# string to the user's shell. We loop reading output until we see the randomly-generated
# sudo prompt set with the -p option.
prompt
=
'[sudo via ansible, key=
%
s] password: '
%
randbits
# force quick error if password is required but not supplied, should prevent sudo hangs.
if
not
self
.
become_pass
:
flags
+=
" -n "
if
self
.
become_pass
:
prompt
=
'[sudo via ansible, key=
%
s] password: '
%
randbits
becomecmd
=
'
%
s
%
s -p "
%
s" -S -u
%
s
%
s -c
%
s'
%
(
exe
,
flags
,
prompt
,
self
.
become_user
,
executable
,
success_cmd
)
else
:
becomecmd
=
'
%
s
%
s -n -S -u
%
s
%
s -c
%
s'
%
(
exe
,
flags
,
self
.
become_user
,
executable
,
success_cmd
)
becomecmd
=
'
%
s
%
s -S -p "
%
s" -u
%
s
%
s -c
%
s'
%
(
exe
,
flags
,
prompt
,
self
.
become_user
,
executable
,
success_cmd
)
elif
self
.
become_method
==
'su'
:
...
...
@@ -415,6 +417,7 @@ class PlayContext(Base):
else
:
raise
AnsibleError
(
"Privilege escalation method not found:
%
s"
%
self
.
become_method
)
if
self
.
become_pass
:
self
.
prompt
=
prompt
self
.
success_key
=
success_key
return
(
'
%
s -c
%
s'
%
(
executable
,
pipes
.
quote
(
becomecmd
)))
...
...
lib/ansible/plugins/connections/local.py
View file @
4705409c
...
...
@@ -70,7 +70,7 @@ class Connection(ConnectionBase):
)
self
.
_display
.
debug
(
"done running command with Popen()"
)
if
self
.
_play_context
.
prompt
and
self
.
_play_context
.
become_pass
and
sudoable
:
if
self
.
_play_context
.
prompt
and
sudoable
:
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
)
become_output
=
''
...
...
lib/ansible/plugins/connections/paramiko_ssh.py
View file @
4705409c
...
...
@@ -224,7 +224,6 @@ class Connection(ConnectionBase):
try
:
chan
.
exec_command
(
cmd
)
if
self
.
_play_context
.
prompt
:
if
self
.
_play_context
.
become
and
self
.
_play_context
.
become_pass
:
passprompt
=
False
while
True
:
self
.
_display
.
debug
(
'Waiting for Privilege Escalation input'
)
...
...
lib/ansible/plugins/connections/ssh.py
View file @
4705409c
...
...
@@ -378,7 +378,6 @@ class Connection(ConnectionBase):
self
.
_display
.
debug
(
"Handling privilege escalation password prompt."
)
if
self
.
_play_context
.
become
and
self
.
_play_context
.
become_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
)
...
...
test/units/playbook/test_play_context.py
View file @
4705409c
...
...
@@ -116,7 +116,7 @@ class TestPlayContext(unittest.TestCase):
default_cmd
=
"/bin/foo"
default_exe
=
"/bin/bash"
sudo_exe
=
C
.
DEFAULT_SUDO_EXE
or
'sudo'
sudo_flags
=
C
.
DEFAULT_SUDO_FLAGS
+
" -n "
sudo_flags
=
C
.
DEFAULT_SUDO_FLAGS
su_exe
=
C
.
DEFAULT_SU_EXE
or
'su'
su_flags
=
C
.
DEFAULT_SU_FLAGS
or
''
pbrun_exe
=
'pbrun'
...
...
@@ -134,7 +134,12 @@ class TestPlayContext(unittest.TestCase):
play_context
.
become_method
=
'sudo'
cmd
=
play_context
.
make_become_cmd
(
cmd
=
default_cmd
,
executable
=
"/bin/bash"
)
self
.
assertEqual
(
cmd
,
"""
%
s -c '
%
s
%
s -S -p "
%
s" -u
%
s
%
s -c '"'"'echo
%
s;
%
s'"'"''"""
%
(
default_exe
,
sudo_exe
,
sudo_flags
,
play_context
.
prompt
,
play_context
.
become_user
,
default_exe
,
play_context
.
success_key
,
default_cmd
))
self
.
assertEqual
(
cmd
,
"""
%
s -c '
%
s
%
s -n -S -u
%
s
%
s -c '"'"'echo
%
s;
%
s'"'"''"""
%
(
default_exe
,
sudo_exe
,
sudo_flags
,
play_context
.
become_user
,
default_exe
,
play_context
.
success_key
,
default_cmd
))
play_context
.
become_pass
=
'testpass'
cmd
=
play_context
.
make_become_cmd
(
cmd
=
default_cmd
,
executable
=
default_exe
)
self
.
assertEqual
(
cmd
,
"""
%
s -c '
%
s
%
s -p "
%
s" -S -u
%
s
%
s -c '"'"'echo
%
s;
%
s'"'"''"""
%
(
default_exe
,
sudo_exe
,
sudo_flags
,
play_context
.
prompt
,
play_context
.
become_user
,
default_exe
,
play_context
.
success_key
,
default_cmd
))
play_context
.
become_pass
=
None
play_context
.
become_method
=
'su'
cmd
=
play_context
.
make_become_cmd
(
cmd
=
default_cmd
,
executable
=
"/bin/bash"
)
...
...
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