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
6cceaa5f
Commit
6cceaa5f
authored
Feb 24, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implment copy with an actual minion-side module such that we can get md5sum's and
onchange events like Puppet's file providers do.
parent
440bac4a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
84 additions
and
9 deletions
+84
-9
examples/playbook.yml
+4
-0
lib/ansible/runner.py
+40
-8
library/copy
+40
-1
No files found.
examples/playbook.yml
View file @
6cceaa5f
-
pattern
:
'
*'
tasks
:
-
do
:
-
copy a file
-
copy
-
[
"
/srv/a"
,
"
/srv/b"
]
-
do
:
-
configure template & module variables
-
setup
-
[
"
a=2"
,
"
b=3"
,
"
c=4"
]
...
...
lib/ansible/runner.py
View file @
6cceaa5f
...
...
@@ -122,16 +122,46 @@ class Runner(object):
try
:
return
[
host
,
True
,
json
.
loads
(
result
)
]
except
:
traceback
.
print_exc
()
return
[
host
,
False
,
result
]
elif
self
.
module_name
==
'copy'
:
# SFTP file copy module is not really a module
# TODO: major refactoring pending
# do sftp then run actual copy module to get change info
self
.
remote_log
(
conn
,
'COPY remote:
%
s local:
%
s'
%
(
self
.
module_args
[
0
],
self
.
module_args
[
1
]))
source
=
self
.
module_args
[
0
]
dest
=
self
.
module_args
[
1
]
tmp_dest
=
self
.
_get_tmp_path
(
conn
,
dest
.
split
(
"/"
)[
-
1
])
ftp
=
conn
.
open_sftp
()
ftp
.
put
(
s
elf
.
module_args
[
0
],
self
.
module_args
[
1
]
)
ftp
.
put
(
s
ource
,
tmp_dest
)
ftp
.
close
()
# install the copy module
self
.
module_name
=
'copy'
outpath
=
self
.
_copy_module
(
conn
)
self
.
_exec_command
(
conn
,
"chmod +x
%
s"
%
outpath
)
# run the copy module
self
.
module_args
=
[
tmp_dest
,
dest
]
cmd
=
self
.
_command
(
outpath
)
result
=
self
.
_exec_command
(
conn
,
cmd
)
# remove the module
self
.
_exec_command
(
conn
,
"rm -f
%
s"
%
outpath
)
# remove the temp file
self
.
_exec_command
(
conn
,
"rm -f
%
s"
%
tmp_dest
)
conn
.
close
()
try
:
return
[
host
,
True
,
json
.
loads
(
result
)
]
except
:
traceback
.
print_exc
()
return
[
host
,
False
,
result
]
return
[
host
,
True
,
1
]
elif
self
.
module_name
==
'template'
:
...
...
@@ -155,17 +185,16 @@ class Runner(object):
# install the template module
self
.
module_name
=
'template'
self
.
module_args
=
[
source
,
temppath
]
outpath
=
self
.
_copy_module
(
conn
)
self
.
_exec_command
(
conn
,
"chmod +x
%
s"
%
outpath
)
# run the template module
self
.
module_args
=
[
temppath
,
dest
,
metadata
]
self
.
_exec_command
(
conn
,
"chmod +x
%
s"
%
outpath
)
result
=
self
.
_exec_command
(
conn
,
self
.
_command
(
outpath
))
# clean up
self
.
_exec_command
(
conn
,
"rm -f
%
s"
%
outpath
)
self
.
_exec_command
(
conn
,
"rm -f
%
s"
%
temppath
)
# TODO: remove tmppath
conn
.
close
()
try
:
return
[
host
,
True
,
json
.
loads
(
result
)
]
...
...
@@ -219,9 +248,12 @@ class Runner(object):
hosts
=
self
.
match_hosts
()
# attack pool of hosts in N forks
pool
=
multiprocessing
.
Pool
(
self
.
forks
)
hosts
=
[
(
self
,
x
)
for
x
in
hosts
]
results
=
pool
.
map
(
_executor_hook
,
hosts
)
if
self
.
forks
>
1
:
pool
=
multiprocessing
.
Pool
(
self
.
forks
)
results
=
pool
.
map
(
_executor_hook
,
hosts
)
else
:
results
=
[
_executor_hook
(
x
)
for
x
in
hosts
]
# sort hosts by ones we successfully contacted
# and ones we did not
...
...
library/copy
View file @
6cceaa5f
# copy is built-in to ansible's core, so the module here is just a placeholder
#!/usr/bin/python
import
sys
import
os
try
:
import
json
except
ImportError
:
import
simplejson
as
json
source
=
sys
.
argv
[
1
]
dest
=
sys
.
argv
[
2
]
# raise an error if there is no source file
if
not
os
.
path
.
exists
(
source
):
print
json
.
dumps
({
"failed"
:
1
,
"msg"
:
"Source
%
s failed to transfer"
%
source
})
sys
.
exit
(
1
)
md5sum
=
None
changed
=
False
if
os
.
path
.
exists
(
dest
):
md5sum
=
os
.
popen
(
"md5sum
%
s"
%
dest
)
.
read
()
os
.
system
(
"cp
%
s
%
s"
%
(
source
,
dest
))
md5sum2
=
os
.
popen
(
"md5sum
%
s"
%
dest
)
.
read
()
if
md5sum
!=
md5sum2
:
changed
=
True
# mission accomplished
print
json
.
dumps
({
"md5sum"
:
md5sum2
,
"changed"
:
changed
})
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