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
3dc31a04
Commit
3dc31a04
authored
Nov 08, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1527 from fdavis/devel
Support scp in an ssh connection
parents
36c1b4be
b91896ff
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
8 deletions
+27
-8
examples/ansible.cfg
+4
-0
lib/ansible/constants.py
+1
-0
lib/ansible/runner/connection_plugins/ssh.py
+22
-8
No files found.
examples/ansible.cfg
View file @
3dc31a04
...
...
@@ -104,4 +104,8 @@ vars_plugins = /usr/share/ansible_plugins/vars_plugins
ssh_args=-o PasswordAuthentication=no -o ControlMaster=auto -o ControlPersist=60s -o ControlPath=/tmp/ansible-ssh-%h-%p-%r
# the following makes ansible use scp if the connection type is ssh (default is sftp)
#scp_if_ssh=True
lib/ansible/constants.py
View file @
3dc31a04
...
...
@@ -86,6 +86,7 @@ DEFAULT_SUDO_USER = get_config(p, DEFAULTS, 'sudo_user', 'ANSIBLE
DEFAULT_ASK_SUDO_PASS
=
get_config
(
p
,
DEFAULTS
,
'ask_sudo_pass'
,
'ANSIBLE_ASK_SUDO_PASS'
,
False
)
DEFAULT_REMOTE_PORT
=
int
(
get_config
(
p
,
DEFAULTS
,
'remote_port'
,
'ANSIBLE_REMOTE_PORT'
,
22
))
DEFAULT_TRANSPORT
=
get_config
(
p
,
DEFAULTS
,
'transport'
,
'ANSIBLE_TRANSPORT'
,
'paramiko'
)
DEFAULT_SCP_IF_SSH
=
get_config
(
p
,
DEFAULTS
,
'scp_if_ssh'
,
'ANSIBLE_SCP_IF_SSH'
,
False
)
DEFAULT_MANAGED_STR
=
get_config
(
p
,
DEFAULTS
,
'ansible_managed'
,
None
,
'Ansible managed: {file} modified on
%
Y-
%
m-
%
d
%
H:
%
M:
%
S by {uid} on {host}'
)
DEFAULT_ACTION_PLUGIN_PATH
=
shell_expand_path
(
get_config
(
p
,
DEFAULTS
,
'action_plugins'
,
None
,
'/usr/share/ansible_plugins/action_plugins'
))
...
...
lib/ansible/runner/connection_plugins/ssh.py
View file @
3dc31a04
...
...
@@ -118,20 +118,34 @@ class Connection(object):
vvv
(
"PUT
%
s TO
%
s"
%
(
in_path
,
out_path
),
host
=
self
.
host
)
if
not
os
.
path
.
exists
(
in_path
):
raise
errors
.
AnsibleFileNotFound
(
"file or module does not exist:
%
s"
%
in_path
)
sftp_cmd
=
[
"sftp"
]
+
self
.
common_args
+
[
self
.
host
]
p
=
subprocess
.
Popen
(
sftp_cmd
,
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
stdout
,
stderr
=
p
.
communicate
(
"put
%
s
%
s
\n
"
%
(
in_path
,
out_path
))
if
C
.
DEFAULT_SCP_IF_SSH
:
ft_cmd
=
[
"scp"
]
+
self
.
common_args
ft_cmd
+=
[
in_path
,
self
.
host
+
":"
+
out_path
]
p
=
subprocess
.
Popen
(
ft_cmd
,
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
stdout
,
stderr
=
p
.
communicate
()
else
:
sftp_cmd
=
[
"sftp"
]
+
self
.
common_args
+
[
self
.
host
]
p
=
subprocess
.
Popen
(
sftp_cmd
,
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
stdout
,
stderr
=
p
.
communicate
(
"put
%
s
%
s
\n
"
%
(
in_path
,
out_path
))
if
p
.
returncode
!=
0
:
raise
errors
.
AnsibleError
(
"failed to transfer file to
%
s:
\n
%
s
\n
%
s"
%
(
out_path
,
stdout
,
stderr
))
def
fetch_file
(
self
,
in_path
,
out_path
):
''' fetch a file from remote to local '''
vvv
(
"FETCH
%
s TO
%
s"
%
(
in_path
,
out_path
),
host
=
self
.
host
)
sftp_cmd
=
[
"sftp"
]
+
self
.
common_args
+
[
self
.
host
]
p
=
subprocess
.
Popen
(
sftp_cmd
,
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
stdout
,
stderr
=
p
.
communicate
(
"get
%
s
%
s
\n
"
%
(
in_path
,
out_path
))
if
C
.
DEFAULT_SCP_IF_SSH
:
ft_cmd
=
[
"scp"
]
+
self
.
common_args
ft_cmd
+=
[
self
.
host
+
":"
+
in_path
,
out_path
]
p
=
subprocess
.
Popen
(
ft_cmd
,
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
stdout
,
stderr
=
p
.
communicate
()
else
:
sftp_cmd
=
[
"sftp"
]
+
self
.
common_args
+
[
self
.
host
]
p
=
subprocess
.
Popen
(
sftp_cmd
,
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
stdout
,
stderr
=
p
.
communicate
(
"get
%
s
%
s
\n
"
%
(
in_path
,
out_path
))
if
p
.
returncode
!=
0
:
raise
errors
.
AnsibleError
(
"failed to transfer file from
%
s:
\n
%
s
\n
%
s"
%
(
in_path
,
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