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
62224271
Commit
62224271
authored
Apr 11, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #131 from mgwilliams/feature-fetch-module
Fetch Module
parents
51e4faf7
31d3f52b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
85 additions
and
0 deletions
+85
-0
lib/ansible/connection.py
+13
-0
lib/ansible/runner.py
+48
-0
library/fetch
+24
-0
No files found.
lib/ansible/connection.py
View file @
62224271
...
@@ -142,6 +142,15 @@ class ParamikoConnection(object):
...
@@ -142,6 +142,15 @@ class ParamikoConnection(object):
raise
errors
.
AnsibleError
(
"failed to transfer file to
%
s"
%
out_path
)
raise
errors
.
AnsibleError
(
"failed to transfer file to
%
s"
%
out_path
)
sftp
.
close
()
sftp
.
close
()
def
fetch_file
(
self
,
in_path
,
out_path
):
sftp
=
self
.
ssh
.
open_sftp
()
try
:
sftp
.
get
(
in_path
,
out_path
)
except
IOError
:
traceback
.
print_exc
()
raise
errors
.
AnsibleError
(
"failed to transfer file from
%
s"
%
in_path
)
sftp
.
close
()
def
close
(
self
):
def
close
(
self
):
''' terminate the connection '''
''' terminate the connection '''
...
@@ -184,6 +193,10 @@ class LocalConnection(object):
...
@@ -184,6 +193,10 @@ class LocalConnection(object):
traceback
.
print_exc
()
traceback
.
print_exc
()
raise
errors
.
AnsibleError
(
"failed to transfer file to
%
s"
%
out_path
)
raise
errors
.
AnsibleError
(
"failed to transfer file to
%
s"
%
out_path
)
def
fetch_file
(
self
,
in_path
,
out_path
):
''' fetch a file from local to local -- for copatibility '''
self
.
put_file
(
in_path
,
out_path
)
def
close
(
self
):
def
close
(
self
):
''' terminate the connection; nothing to do here '''
''' terminate the connection; nothing to do here '''
...
...
lib/ansible/runner.py
View file @
62224271
...
@@ -486,6 +486,52 @@ class Runner(object):
...
@@ -486,6 +486,52 @@ class Runner(object):
# *****************************************************
# *****************************************************
def
_execute_fetch
(
self
,
conn
,
host
,
tmp
):
''' handler for fetch operations '''
#load up options
options
=
utils
.
parse_kv
(
self
.
module_args
)
source
=
options
[
'src'
]
filename
=
os
.
path
.
basename
(
source
)
dest
=
"
%
s/
%
s/
%
s"
%
(
options
[
'dest'
],
host
,
filename
)
changed
=
False
failed
=
None
ok
=
True
error
=
None
#get old md5
local_md5
=
None
if
os
.
path
.
exists
(
dest
):
local_md5
=
os
.
popen
(
"md5sum
%
s"
%
dest
)
.
read
()
.
split
()[
0
]
#get new md5
remote_md5
=
self
.
_exec_command
(
conn
,
"md5sum
%
s"
%
source
,
tmp
,
True
)[
0
]
.
split
()[
0
]
if
remote_md5
!=
local_md5
:
#create the containing directories, if needed
os
.
makedirs
(
os
.
path
.
dirname
(
dest
))
#fetch the file and check for changes
conn
.
fetch_file
(
source
,
dest
)
new_md5
=
os
.
popen
(
"md5sum
%
s"
%
dest
)
.
read
()
.
split
()[
0
]
changed
=
(
new_md5
!=
local_md5
)
if
new_md5
!=
remote_md5
:
error
=
"new md5 does not match remote md5"
else
:
new_md5
=
local_md5
if
error
:
ok
=
False
failed
=
True
data
=
{
'msg'
:
error
,
'failed'
:
True
,
'md5sum'
:
new_md5
,
'changed'
:
changed
}
else
:
data
=
{
'changed'
:
changed
,
'md5sum'
:
new_md5
}
return
(
host
,
ok
,
data
,
failed
)
# *****************************************************
def
_chain_file_module
(
self
,
conn
,
tmp
,
data
,
err
,
options
,
executed
):
def
_chain_file_module
(
self
,
conn
,
tmp
,
data
,
err
,
options
,
executed
):
''' handles changing file attribs after copy/template operations '''
''' handles changing file attribs after copy/template operations '''
...
@@ -575,6 +621,8 @@ class Runner(object):
...
@@ -575,6 +621,8 @@ class Runner(object):
if
self
.
module_name
==
'copy'
:
if
self
.
module_name
==
'copy'
:
result
=
self
.
_execute_copy
(
conn
,
host
,
tmp
)
result
=
self
.
_execute_copy
(
conn
,
host
,
tmp
)
elif
self
.
module_name
==
'fetch'
:
result
=
self
.
_execute_fetch
(
conn
,
host
,
tmp
)
elif
self
.
module_name
==
'template'
:
elif
self
.
module_name
==
'template'
:
result
=
self
.
_execute_template
(
conn
,
host
,
tmp
)
result
=
self
.
_execute_template
(
conn
,
host
,
tmp
)
else
:
else
:
...
...
library/fetch
0 → 100755
View file @
62224271
#!/usr/bin/python
# (c) 2012, Michael DeHaan <michael.dehaan@gmail.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
### THIS FILE IS FOR REFERENCE OR FUTURE USE ###
# See lib/ansible/runner.py for implementation of the fetch functionality #
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