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
c811668a
Commit
c811668a
authored
Sep 28, 2015
by
Toshio Kuratomi
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #12546 from amenonsen/ssh-cleanups
A couple of ssh cleanups
parents
05af4c8e
38c7422d
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
39 deletions
+52
-39
lib/ansible/plugins/connection/ssh.py
+52
-39
No files found.
lib/ansible/plugins/connection/ssh.py
View file @
c811668a
...
...
@@ -92,21 +92,7 @@ class Connection(ConnectionBase):
# write the password to sshpass.
if
self
.
_play_context
.
password
:
global
SSHPASS_AVAILABLE
# We test once if sshpass is available, and remember the result. It
# would be nice to use distutils.spawn.find_executable for this, but
# distutils isn't always available; shutils.which() is Python3-only.
if
SSHPASS_AVAILABLE
is
None
:
try
:
p
=
subprocess
.
Popen
([
"sshpass"
],
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
p
.
communicate
()
SSHPASS_AVAILABLE
=
True
except
OSError
:
SSHPASS_AVAILABLE
=
False
if
not
SSHPASS_AVAILABLE
:
if
not
self
.
_sshpass_available
():
raise
AnsibleError
(
"to use the 'ssh' connection type with passwords, you must install the sshpass program"
)
self
.
sshpass_pipe
=
os
.
pipe
()
...
...
@@ -204,36 +190,27 @@ class Connection(ConnectionBase):
args
=
self
.
_split_args
(
self
.
ssh_extra_args
)
self
.
add_args
(
"inventory added ansible_ssh_extra_args"
,
args
)
# If ssh_args or ssh_extra_args set ControlPersist but not a
# ControlPath, add one ourselves.
# Check if ControlPersist is enabled (either by default, or using
# ssh_args or ssh_extra_args) and add a ControlPath if one hasn't
# already been set.
cp_in_use
=
False
cp_path_set
=
False
for
arg
in
self
.
_command
:
if
"ControlPersist"
in
arg
:
cp_in_use
=
True
if
"ControlPath"
in
arg
:
cp_path_set
=
True
controlpersist
,
controlpath
=
self
.
_persistence_controls
(
self
.
_command
)
if
c
p_in_use
and
not
cp_path_se
t
:
self
.
_
cp_dir
=
unfrackpath
(
'$HOME/.ansible/cp'
)
if
c
ontrolpersis
t
:
self
.
_
persistent
=
True
args
=
(
"-o"
,
"ControlPath={0}"
.
format
(
C
.
ANSIBLE_SSH_CONTROL_PATH
%
dict
(
directory
=
self
.
_cp_dir
))
)
self
.
add_args
(
"found only ControlPersist; added ControlPath"
,
args
)
if
not
controlpath
:
cpdir
=
unfrackpath
(
'$HOME/.ansible/cp'
)
# The directory must exist and be writable.
makedirs_safe
(
self
.
_cp_dir
,
0
o700
)
if
not
os
.
access
(
self
.
_cp_dir
,
os
.
W_OK
):
raise
AnsibleError
(
"Cannot write to ControlPath
%
s"
%
self
.
_cp_dir
)
# If the configuration dictates that we use a persistent connection,
# then we remember that for later. (We could be more thorough about
# detecting this, though.)
makedirs_safe
(
cpdir
,
0
o700
)
if
not
os
.
access
(
cpdir
,
os
.
W_OK
):
raise
AnsibleError
(
"Cannot write to ControlPath
%
s"
%
cpdir
)
if
cp_in_use
:
self
.
_persistent
=
True
args
=
(
"-o"
,
"ControlPath={0}"
.
format
(
C
.
ANSIBLE_SSH_CONTROL_PATH
%
dict
(
directory
=
cpdir
))
)
self
.
add_args
(
"found only ControlPersist; added ControlPath"
,
args
)
## Finally, we add any caller-supplied extras.
...
...
@@ -646,6 +623,42 @@ class Connection(ConnectionBase):
# Utility functions
def
_sshpass_available
(
self
):
global
SSHPASS_AVAILABLE
# We test once if sshpass is available, and remember the result. It
# would be nice to use distutils.spawn.find_executable for this, but
# distutils isn't always available; shutils.which() is Python3-only.
if
SSHPASS_AVAILABLE
is
None
:
try
:
p
=
subprocess
.
Popen
([
"sshpass"
],
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
p
.
communicate
()
SSHPASS_AVAILABLE
=
True
except
OSError
:
SSHPASS_AVAILABLE
=
False
return
SSHPASS_AVAILABLE
def
_persistence_controls
(
self
,
command
):
'''
Takes a command array and scans it for ControlPersist and ControlPath
settings and returns two booleans indicating whether either was found.
This could be smarter, e.g. returning false if ControlPersist is 'no',
but for now we do it simple way.
'''
controlpersist
=
False
controlpath
=
False
for
arg
in
command
:
if
'controlpersist'
in
arg
.
lower
():
controlpersist
=
True
elif
'controlpath'
in
arg
.
lower
():
controlpath
=
True
return
controlpersist
,
controlpath
def
_terminate_process
(
self
,
p
):
try
:
p
.
terminate
()
...
...
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