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
9ce46e5f
Commit
9ce46e5f
authored
Feb 10, 2014
by
James Tanner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor the synchronize action plugin and add unit tests
parent
f858679f
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
4 deletions
+37
-4
lib/ansible/runner/action_plugins/synchronize.py
+37
-4
No files found.
lib/ansible/runner/action_plugins/synchronize.py
View file @
9ce46e5f
...
@@ -36,10 +36,13 @@ class ActionModule(object):
...
@@ -36,10 +36,13 @@ class ActionModule(object):
def
_process_remote
(
self
,
host
,
path
,
user
):
def
_process_remote
(
self
,
host
,
path
,
user
):
transport
=
self
.
runner
.
transport
transport
=
self
.
runner
.
transport
return_data
=
None
if
not
host
in
[
'127.0.0.1'
,
'localhost'
]
or
transport
!=
"local"
:
if
not
host
in
[
'127.0.0.1'
,
'localhost'
]
or
transport
!=
"local"
:
return
'
%
s@
%
s:
%
s'
%
(
user
,
host
,
path
)
return
_data
=
'
%
s@
%
s:
%
s'
%
(
user
,
host
,
path
)
else
:
else
:
return
path
return_data
=
path
return
return_data
def
setup
(
self
,
module_name
,
inject
):
def
setup
(
self
,
module_name
,
inject
):
''' Always default to localhost as delegate if None defined '''
''' Always default to localhost as delegate if None defined '''
...
@@ -63,7 +66,6 @@ class ActionModule(object):
...
@@ -63,7 +66,6 @@ class ActionModule(object):
''' generates params and passes them on to the rsync module '''
''' generates params and passes them on to the rsync module '''
# load up options
# load up options
options
=
{}
options
=
{}
if
complex_args
:
if
complex_args
:
options
.
update
(
complex_args
)
options
.
update
(
complex_args
)
...
@@ -83,26 +85,56 @@ class ActionModule(object):
...
@@ -83,26 +85,56 @@ class ActionModule(object):
# from the perspective of the rsync call the delegate is the localhost
# from the perspective of the rsync call the delegate is the localhost
src_host
=
'127.0.0.1'
src_host
=
'127.0.0.1'
dest_host
=
inject
.
get
(
'ansible_ssh_host'
,
inject
[
'inventory_hostname'
])
dest_host
=
inject
.
get
(
'ansible_ssh_host'
,
inject
[
'inventory_hostname'
])
# allow ansible_ssh_host to be templated
# allow ansible_ssh_host to be templated
dest_host
=
template
.
template
(
self
.
runner
.
basedir
,
dest_host
,
inject
,
fail_on_undefined
=
True
)
dest_host
=
template
.
template
(
self
.
runner
.
basedir
,
dest_host
,
inject
,
fail_on_undefined
=
True
)
dest_is_local
=
dest_host
in
[
'127.0.0.1'
,
'localhost'
]
dest_is_local
=
dest_host
in
[
'127.0.0.1'
,
'localhost'
]
# CHECK FOR NON-DEFAULT SSH PORT
dest_port
=
options
.
get
(
'dest_port'
)
dest_port
=
options
.
get
(
'dest_port'
)
inv_port
=
inject
.
get
(
'ansible_ssh_port'
,
inject
[
'inventory_hostname'
])
inv_port
=
inject
.
get
(
'ansible_ssh_port'
,
inject
[
'inventory_hostname'
])
if
inv_port
!=
dest_port
and
inv_port
!=
inject
[
'inventory_hostname'
]:
if
inv_port
!=
dest_port
and
inv_port
!=
inject
[
'inventory_hostname'
]:
options
[
'dest_port'
]
=
inv_port
options
[
'dest_port'
]
=
inv_port
# edge case: explicit delegate and dest_host are the same
# edge case: explicit delegate and dest_host are the same
if
dest_host
==
inject
[
'delegate_to'
]:
if
dest_host
==
inject
[
'delegate_to'
]:
dest_host
=
'127.0.0.1'
dest_host
=
'127.0.0.1'
# SWITCH SRC AND DEST PER MODE
if
options
.
get
(
'mode'
,
'push'
)
==
'pull'
:
if
options
.
get
(
'mode'
,
'push'
)
==
'pull'
:
(
dest_host
,
src_host
)
=
(
src_host
,
dest_host
)
(
dest_host
,
src_host
)
=
(
src_host
,
dest_host
)
# CHECK DELEGATE HOST INFO
use_delegate
=
False
if
conn
.
delegate
!=
conn
.
host
:
if
'hostvars'
in
inject
:
if
conn
.
delegate
in
inject
[
'hostvars'
]
and
self
.
original_transport
!=
'local'
:
# use a delegate host instead of localhost
use_delegate
=
True
# COMPARE DELEGATE, HOST AND TRANSPORT
process_args
=
False
if
not
dest_host
is
src_host
and
self
.
original_transport
!=
'local'
:
if
not
dest_host
is
src_host
and
self
.
original_transport
!=
'local'
:
# interpret and inject remote host info into src or dest
process_args
=
True
# MUNGE SRC AND DEST PER REMOTE_HOST INFO
if
process_args
or
use_delegate
:
user
=
None
if
use_delegate
:
user
=
inject
[
'hostvars'
][
conn
.
delegate
]
.
get
(
'ansible_ssh_user'
)
if
not
use_delegate
or
not
user
:
user
=
inject
.
get
(
'ansible_ssh_user'
,
user
=
inject
.
get
(
'ansible_ssh_user'
,
self
.
runner
.
remote_user
)
self
.
runner
.
remote_user
)
if
use_delegate
:
# FIXME
private_key
=
inject
.
get
(
'ansible_ssh_private_key_file'
,
self
.
runner
.
private_key_file
)
private_key
=
inject
.
get
(
'ansible_ssh_private_key_file'
,
self
.
runner
.
private_key_file
)
else
:
private_key
=
inject
.
get
(
'ansible_ssh_private_key_file'
,
self
.
runner
.
private_key_file
)
if
not
private_key
is
None
:
if
not
private_key
is
None
:
private_key
=
os
.
path
.
expanduser
(
private_key
)
private_key
=
os
.
path
.
expanduser
(
private_key
)
options
[
'private_key'
]
=
private_key
options
[
'private_key'
]
=
private_key
...
@@ -135,6 +167,7 @@ class ActionModule(object):
...
@@ -135,6 +167,7 @@ class ActionModule(object):
module_items
=
' '
.
join
([
'
%
s=
%
s'
%
(
k
,
v
)
for
(
k
,
module_items
=
' '
.
join
([
'
%
s=
%
s'
%
(
k
,
v
)
for
(
k
,
v
)
in
options
.
items
()])
v
)
in
options
.
items
()])
return
self
.
runner
.
_execute_module
(
conn
,
tmp
,
'synchronize'
,
return
self
.
runner
.
_execute_module
(
conn
,
tmp
,
'synchronize'
,
module_items
,
inject
=
inject
)
module_items
,
inject
=
inject
)
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