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
00daf43a
Commit
00daf43a
authored
Jul 31, 2015
by
James Cammarata
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #11822 from ansible/synchronize-fix2
Fixes for synchronize with delegate_to
parents
21542124
0d72be39
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
14 deletions
+33
-14
lib/ansible/playbook/play_context.py
+13
-1
lib/ansible/plugins/action/synchronize.py
+20
-13
No files found.
lib/ansible/playbook/play_context.py
View file @
00daf43a
...
@@ -134,6 +134,18 @@ SU_PROMPT_LOCALIZATIONS = [
...
@@ -134,6 +134,18 @@ SU_PROMPT_LOCALIZATIONS = [
'密碼'
,
'密碼'
,
]
]
TASK_ATTRIBUTE_OVERRIDES
=
(
'become'
,
'become_user'
,
'become_pass'
,
'become_method'
,
'connection'
,
'delegate_to'
,
'no_log'
,
'remote_user'
,
)
class
PlayContext
(
Base
):
class
PlayContext
(
Base
):
'''
'''
...
@@ -285,7 +297,7 @@ class PlayContext(Base):
...
@@ -285,7 +297,7 @@ class PlayContext(Base):
# loop through a subset of attributes on the task object and set
# loop through a subset of attributes on the task object and set
# connection fields based on their values
# connection fields based on their values
for
attr
in
(
'connection'
,
'remote_user'
,
'become'
,
'become_user'
,
'become_pass'
,
'become_method'
,
'no_log'
)
:
for
attr
in
TASK_ATTRIBUTE_OVERRIDES
:
if
hasattr
(
task
,
attr
):
if
hasattr
(
task
,
attr
):
attr_val
=
getattr
(
task
,
attr
)
attr_val
=
getattr
(
task
,
attr
)
if
attr_val
is
not
None
:
if
attr_val
is
not
None
:
...
...
lib/ansible/plugins/action/synchronize.py
View file @
00daf43a
...
@@ -75,13 +75,10 @@ class ActionModule(ActionBase):
...
@@ -75,13 +75,10 @@ class ActionModule(ActionBase):
original_transport
=
task_vars
.
get
(
'ansible_connection'
)
or
self
.
_play_context
.
connection
original_transport
=
task_vars
.
get
(
'ansible_connection'
)
or
self
.
_play_context
.
connection
transport_overridden
=
False
transport_overridden
=
False
if
task_vars
.
get
(
'delegate_to'
)
is
None
:
try
:
task_vars
[
'delegate_to'
]
=
'127.0.0.1'
delegate_to
=
self
.
_play_context
.
delegate_to
# IF original transport is not local, override transport and disable sudo.
except
(
AttributeError
,
KeyError
):
if
original_transport
!=
'local'
:
delegate_to
=
None
task_vars
[
'ansible_connection'
]
=
'local'
transport_overridden
=
True
self
.
_play_context
.
become
=
False
use_ssh_args
=
self
.
_task
.
args
.
pop
(
'use_ssh_args'
,
None
)
use_ssh_args
=
self
.
_task
.
args
.
pop
(
'use_ssh_args'
,
None
)
...
@@ -103,13 +100,15 @@ class ActionModule(ActionBase):
...
@@ -103,13 +100,15 @@ class ActionModule(ActionBase):
# CHECK DELEGATE HOST INFO
# CHECK DELEGATE HOST INFO
use_delegate
=
False
use_delegate
=
False
if
dest_host
==
task_vars
.
get
(
'delegate_to'
)
:
if
dest_host
==
delegate_to
:
# edge case: explicit delegate and dest_host are the same
# edge case: explicit delegate and dest_host are the same
# so we run rsync on the remote machine targetting its localhost
# (itself)
dest_host
=
'127.0.0.1'
dest_host
=
'127.0.0.1'
use_delegate
=
True
use_delegate
=
True
else
:
else
:
if
'hostvars'
in
task_vars
:
if
'hostvars'
in
task_vars
:
if
task_vars
.
get
(
'delegate_to'
)
in
task_vars
[
'hostvars'
]
and
original_transport
!=
'local'
:
if
delegate_to
in
task_vars
[
'hostvars'
]
and
original_transport
!=
'local'
:
# use a delegate host instead of localhost
# use a delegate host instead of localhost
use_delegate
=
True
use_delegate
=
True
...
@@ -126,12 +125,19 @@ class ActionModule(ActionBase):
...
@@ -126,12 +125,19 @@ class ActionModule(ActionBase):
# Delegate to localhost as the source of the rsync unless we've been
# Delegate to localhost as the source of the rsync unless we've been
# told (via delegate_to) that a different host is the source of the
# told (via delegate_to) that a different host is the source of the
# rsync
# rsync
if
not
use_delegate
:
transport_overridden
=
False
if
not
use_delegate
and
original_transport
!=
'local'
:
# Create a connection to localhost to run rsync on
# Create a connection to localhost to run rsync on
### FIXME: Do we have to dupe stdin or is this sufficient?
new_stdin
=
self
.
_connection
.
_new_stdin
new_stdin
=
self
.
_connection
.
_new_stdin
new_connection
=
connection_loader
.
get
(
'local'
,
self
.
_play_context
,
new_stdin
)
new_connection
=
connection_loader
.
get
(
'local'
,
self
.
_play_context
,
new_stdin
)
self
.
_connection
=
new_connection
self
.
_connection
=
new_connection
transport_overridden
=
True
### FIXME: We think that this was here for v1 because the local
# connection didn't support sudo. In v2 it does so we think it's
# safe to remove this now.
# Also disable sudo
#self._play_context.become = False
# MUNGE SRC AND DEST PER REMOTE_HOST INFO
# MUNGE SRC AND DEST PER REMOTE_HOST INFO
src
=
self
.
_task
.
args
.
get
(
'src'
,
None
)
src
=
self
.
_task
.
args
.
get
(
'src'
,
None
)
...
@@ -140,10 +146,11 @@ class ActionModule(ActionBase):
...
@@ -140,10 +146,11 @@ class ActionModule(ActionBase):
user
=
None
user
=
None
if
boolean
(
task_vars
.
get
(
'set_remote_user'
,
'yes'
)):
if
boolean
(
task_vars
.
get
(
'set_remote_user'
,
'yes'
)):
if
use_delegate
:
user
=
task_vars
[
'hostvars'
][
delegate_to
]
.
get
(
'ansible_ssh_user'
)
if
not
use_delegate
or
not
user
:
if
not
use_delegate
or
not
user
:
user
=
task_vars
.
get
(
'ansible_ssh_user'
)
or
self
.
_play_context
.
remote_user
user
=
task_vars
.
get
(
'ansible_ssh_user'
)
or
self
.
_play_context
.
remote_user
elif
use_delegate
:
user
=
task_vars
[
'hostvars'
][
task_vars
.
get
(
'delegate_to'
)]
.
get
(
'ansible_ssh_user'
)
if
use_delegate
:
if
use_delegate
:
private_key
=
task_vars
.
get
(
'ansible_ssh_private_key_file'
)
or
self
.
_play_context
.
private_key_file
private_key
=
task_vars
.
get
(
'ansible_ssh_private_key_file'
)
or
self
.
_play_context
.
private_key_file
...
...
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