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
1804df0b
Commit
1804df0b
authored
Apr 24, 2012
by
Jeroen Hoekx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Whitespace fixes in connection.py
parent
80e6d836
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
26 deletions
+26
-26
lib/ansible/connection.py
+26
-26
No files found.
lib/ansible/connection.py
View file @
1804df0b
...
@@ -76,43 +76,43 @@ class ParamikoConnection(object):
...
@@ -76,43 +76,43 @@ class ParamikoConnection(object):
self
.
port
=
self
.
runner
.
remote_port
self
.
port
=
self
.
runner
.
remote_port
def
_get_conn
(
self
):
def
_get_conn
(
self
):
credentials
=
{}
credentials
=
{}
user
=
self
.
runner
.
remote_user
user
=
self
.
runner
.
remote_user
keypair
=
None
keypair
=
None
# Read file ~/.ssh/config, get data hostname, keyfile, port, etc
# Read file ~/.ssh/config, get data hostname, keyfile, port, etc
# This overrides the ansible defined username,hostname and port
# This overrides the ansible defined username,hostname and port
try
:
try
:
ssh_config
=
paramiko
.
SSHConfig
()
ssh_config
=
paramiko
.
SSHConfig
()
config_file
=
(
'~/.ssh/config'
)
config_file
=
(
'~/.ssh/config'
)
if
os
.
path
.
exists
(
os
.
path
.
expanduser
(
config_file
)):
if
os
.
path
.
exists
(
os
.
path
.
expanduser
(
config_file
)):
ssh_config
.
parse
(
open
(
os
.
path
.
expanduser
(
config_file
)))
ssh_config
.
parse
(
open
(
os
.
path
.
expanduser
(
config_file
)))
credentials
=
ssh_config
.
lookup
(
self
.
host
)
credentials
=
ssh_config
.
lookup
(
self
.
host
)
except
IOError
,
e
:
except
IOError
,
e
:
raise
errors
.
AnsibleConnectionFailed
(
str
(
e
))
raise
errors
.
AnsibleConnectionFailed
(
str
(
e
))
if
'hostname'
in
credentials
:
if
'hostname'
in
credentials
:
self
.
host
=
credentials
[
'hostname'
]
self
.
host
=
credentials
[
'hostname'
]
if
'port'
in
credentials
:
if
'port'
in
credentials
:
self
.
port
=
int
(
credentials
[
'port'
])
self
.
port
=
int
(
credentials
[
'port'
])
if
'user'
in
credentials
:
if
'user'
in
credentials
:
user
=
credentials
[
'user'
]
user
=
credentials
[
'user'
]
if
'identityfile'
in
credentials
:
if
'identityfile'
in
credentials
:
keypair
=
credentials
[
'identityfile'
]
keypair
=
credentials
[
'identityfile'
]
ssh
=
paramiko
.
SSHClient
()
ssh
=
paramiko
.
SSHClient
()
ssh
.
set_missing_host_key_policy
(
paramiko
.
AutoAddPolicy
())
ssh
.
set_missing_host_key_policy
(
paramiko
.
AutoAddPolicy
())
try
:
try
:
ssh
.
connect
(
ssh
.
connect
(
self
.
host
,
self
.
host
,
username
=
user
,
username
=
user
,
allow_agent
=
True
,
allow_agent
=
True
,
look_for_keys
=
True
,
look_for_keys
=
True
,
password
=
self
.
runner
.
remote_pass
,
password
=
self
.
runner
.
remote_pass
,
key_filename
=
keypair
,
key_filename
=
keypair
,
timeout
=
self
.
runner
.
timeout
,
timeout
=
self
.
runner
.
timeout
,
port
=
self
.
port
port
=
self
.
port
)
)
except
Exception
,
e
:
except
Exception
,
e
:
...
@@ -131,7 +131,7 @@ class ParamikoConnection(object):
...
@@ -131,7 +131,7 @@ class ParamikoConnection(object):
def
exec_command
(
self
,
cmd
,
tmp_path
,
sudoable
=
False
):
# pylint: disable-msg=W0613
def
exec_command
(
self
,
cmd
,
tmp_path
,
sudoable
=
False
):
# pylint: disable-msg=W0613
''' run a command on the remote host '''
''' run a command on the remote host '''
if
not
self
.
runner
.
sudo
or
not
sudoable
:
if
not
self
.
runner
.
sudo
or
not
sudoable
:
stdin
,
stdout
,
stderr
=
self
.
ssh
.
exec_command
(
cmd
)
stdin
,
stdout
,
stderr
=
self
.
ssh
.
exec_command
(
cmd
)
return
(
stdin
,
stdout
,
stderr
)
return
(
stdin
,
stdout
,
stderr
)
else
:
else
:
...
@@ -145,7 +145,7 @@ class ParamikoConnection(object):
...
@@ -145,7 +145,7 @@ class ParamikoConnection(object):
bufsize
=
4096
# Could make this a Runner param if needed
bufsize
=
4096
# Could make this a Runner param if needed
timeout_secs
=
self
.
runner
.
timeout
# Reusing runner's TCP connect timeout as command progress timeout
timeout_secs
=
self
.
runner
.
timeout
# Reusing runner's TCP connect timeout as command progress timeout
chan
=
self
.
ssh
.
get_transport
()
.
open_session
()
chan
=
self
.
ssh
.
get_transport
()
.
open_session
()
chan
.
settimeout
(
timeout_secs
)
chan
.
settimeout
(
timeout_secs
)
chan
.
get_pty
()
# Many sudo setups require a terminal
chan
.
get_pty
()
# Many sudo setups require a terminal
#print "exec_command: " + sudocmd
#print "exec_command: " + sudocmd
chan
.
exec_command
(
sudocmd
)
chan
.
exec_command
(
sudocmd
)
...
@@ -153,10 +153,10 @@ class ParamikoConnection(object):
...
@@ -153,10 +153,10 @@ class ParamikoConnection(object):
while
not
chan
.
recv_ready
():
while
not
chan
.
recv_ready
():
time
.
sleep
(
0.25
)
time
.
sleep
(
0.25
)
sudo_output
=
chan
.
recv
(
bufsize
)
# Pull prompt, catch errors, eat sudo output
sudo_output
=
chan
.
recv
(
bufsize
)
# Pull prompt, catch errors, eat sudo output
#print "exec_command: " + sudo_output
#print "exec_command: " + sudo_output
#print "exec_command: sending password"
#print "exec_command: sending password"
chan
.
sendall
(
self
.
runner
.
sudo_pass
+
'
\n
'
)
chan
.
sendall
(
self
.
runner
.
sudo_pass
+
'
\n
'
)
stdin
=
chan
.
makefile
(
'wb'
,
bufsize
)
stdin
=
chan
.
makefile
(
'wb'
,
bufsize
)
stdout
=
chan
.
makefile
(
'rb'
,
bufsize
)
stdout
=
chan
.
makefile
(
'rb'
,
bufsize
)
stderr
=
chan
.
makefile_stderr
(
'rb'
,
bufsize
)
stderr
=
chan
.
makefile_stderr
(
'rb'
,
bufsize
)
...
...
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