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
8cc2f1c4
Commit
8cc2f1c4
authored
Jul 04, 2013
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Lock around SSH connectivity to new hosts in host checking mode such that prompts for host approval
messages do not get interlaced.
parent
9f9373cc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
0 deletions
+32
-0
lib/ansible/runner/connection_plugins/ssh.py
+32
-0
No files found.
lib/ansible/runner/connection_plugins/ssh.py
View file @
8cc2f1c4
...
...
@@ -93,6 +93,22 @@ class Connection(object):
os
.
write
(
self
.
wfd
,
"
%
s
\n
"
%
self
.
password
)
os
.
close
(
self
.
wfd
)
def
not_in_host_file
(
self
,
host
):
host_file
=
os
.
path
.
expanduser
(
"~/.ssh/known_hosts"
)
if
not
os
.
path
.
exists
(
host_file
):
print
"previous known host file not found"
return
True
host_fh
=
open
(
host_file
)
data
=
host_fh
.
read
()
host_fh
.
close
()
for
line
in
data
.
split
(
"
\n
"
):
if
line
is
None
or
line
.
find
(
" "
)
==
-
1
:
continue
tokens
=
line
.
split
()
if
host
in
tokens
[
0
]:
return
False
return
True
def
exec_command
(
self
,
cmd
,
tmp_path
,
sudo_user
,
sudoable
=
False
,
executable
=
'/bin/sh'
):
''' run a command on the remote host '''
...
...
@@ -109,6 +125,16 @@ class Connection(object):
ssh_cmd
.
append
(
sudocmd
)
vvv
(
"EXEC
%
s"
%
ssh_cmd
,
host
=
self
.
host
)
not_in_host_file
=
self
.
not_in_host_file
(
self
.
host
)
if
C
.
HOST_KEY_CHECKING
and
not_in_host_file
:
# lock around the initial SSH connectivity so the user prompt about whether to add
# the host to known hosts is not intermingled with multiprocess output.
KEY_LOCK
=
self
.
runner
.
lockfile
fcntl
.
lockf
(
KEY_LOCK
,
fcntl
.
LOCK_EX
)
try
:
# Make sure stdin is a proper (pseudo) pty to avoid: tcgetattr errors
import
pty
...
...
@@ -161,6 +187,12 @@ class Connection(object):
elif
p
.
poll
()
is
not
None
:
break
stdin
.
close
()
# close stdin after we read from stdout (see also issue #848)
if
C
.
HOST_KEY_CHECKING
and
not_in_host_file
:
# lock around the initial SSH connectivity so the user prompt about whether to add
# the host to known hosts is not intermingled with multiprocess output.
KEY_LOCK
=
self
.
runner
.
lockfile
fcntl
.
lockf
(
KEY_LOCK
,
fcntl
.
LOCK_EX
)
if
p
.
returncode
!=
0
and
stderr
.
find
(
'Bad configuration option: ControlPersist'
)
!=
-
1
:
raise
errors
.
AnsibleError
(
'using -c ssh on certain older ssh versions may not support ControlPersist, set ANSIBLE_SSH_ARGS="" (or ansible_ssh_args in the config file) before running again'
)
...
...
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