Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement docker support for synchronize module. #18145

Merged
merged 2 commits into from
Nov 30, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 19 additions & 4 deletions lib/ansible/plugins/action/synchronize.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def _format_rsync_rsh_target(self, host, path, user):
if path.startswith('rsync://'):
return path

if user:
# If using docker, do not add user information
if self._remote_transport not in [ 'docker' ] and user:
user_prefix = '%s@' % (user, )

if self._host_is_ipv6_address(host):
Expand Down Expand Up @@ -158,6 +159,15 @@ def run(self, tmp=None, task_vars=None):

result = super(ActionModule, self).run(tmp, task_vars)

# Store remote connection type
self._remote_transport = self._connection.transport

# Handle docker connection options
if self._remote_transport == 'docker':
self._docker_cmd = self._connection.docker_cmd
if self._play_context.docker_extra_args:
self._docker_cmd = "%s %s" % (self._docker_cmd, self._play_context.docker_extra_args)

# self._connection accounts for delegate_to so
# remote_transport is the transport ansible thought it would need
# between the controller and the delegate_to host or the controller
Expand All @@ -172,11 +182,11 @@ def run(self, tmp=None, task_vars=None):
except (AttributeError, KeyError):
delegate_to = None

# ssh paramiko and local are fully supported transports. Anything
# ssh paramiko docker and local are fully supported transports. Anything
# else only works with delegate_to
if delegate_to is None and self._connection.transport not in ('ssh', 'paramiko', 'local'):
if delegate_to is None and self._connection.transport not in ('ssh', 'paramiko', 'local', 'docker'):
result['failed'] = True
result['msg'] = "synchronize uses rsync to function. rsync needs to connect to the remote host via ssh or a direct filesystem copy. This remote host is being accessed via %s instead so it cannot work." % self._connection.transport
result['msg'] = "synchronize uses rsync to function. rsync needs to connect to the remote host via ssh, docker client or a direct filesystem copy. This remote host is being accessed via %s instead so it cannot work." % self._connection.transport
return result

use_ssh_args = self._task.args.pop('use_ssh_args', None)
Expand Down Expand Up @@ -341,6 +351,11 @@ def run(self, tmp=None, task_vars=None):
]
self._task.args['ssh_args'] = ' '.join([a for a in ssh_args if a])

# If launching synchronize against docker container
# use rsync_opts to support container to override rsh options
if self._remote_transport in [ 'docker' ]:
self._task.args['rsync_opts'] = "--rsh='%s exec -u %s -i'" % (self._docker_cmd, user)

# run the module and store the result
result.update(self._execute_module('synchronize', task_vars=task_vars))

Expand Down