Merge pull request #13425 from ThomasSteinbach/docker_remote_connection

Allow setup of docker remote connections
This commit is contained in:
Toshio Kuratomi 2016-03-24 15:36:20 -07:00
commit fda3408db3
2 changed files with 19 additions and 4 deletions

View file

@ -65,6 +65,7 @@ MAGIC_VARIABLE_MAPPING = dict(
become_exe = ('ansible_become_exe',),
become_flags = ('ansible_become_flags',),
ssh_common_args = ('ansible_ssh_common_args',),
docker_extra_args= ('ansible_docker_extra_args',),
sftp_extra_args = ('ansible_sftp_extra_args',),
scp_extra_args = ('ansible_scp_extra_args',),
ssh_extra_args = ('ansible_ssh_extra_args',),
@ -121,6 +122,7 @@ TASK_ATTRIBUTE_OVERRIDES = (
'become_pass',
'become_method',
'connection',
'docker_extra_args',
'delegate_to',
'no_log',
'remote_user',
@ -128,6 +130,7 @@ TASK_ATTRIBUTE_OVERRIDES = (
RESET_VARS = (
'ansible_connection',
'ansible_docker_extra_args',
'ansible_ssh_host',
'ansible_ssh_pass',
'ansible_ssh_port',
@ -149,6 +152,7 @@ class PlayContext(Base):
# connection fields, some are inherited from Base:
# (connection, port, remote_user, environment, no_log)
_docker_extra_args = FieldAttribute(isa='string')
_remote_addr = FieldAttribute(isa='string')
_password = FieldAttribute(isa='string')
_private_key_file = FieldAttribute(isa='string', default=C.DEFAULT_PRIVATE_KEY_FILE)
@ -253,6 +257,7 @@ class PlayContext(Base):
options specified by the user on the command line. These have a
lower precedence than those set on the play or host.
'''
# privilege escalation
self.become = options.become
self.become_method = options.become_method
@ -261,7 +266,7 @@ class PlayContext(Base):
self.check_mode = boolean(options.check)
# get ssh options FIXME: make these common to all connections
for flag in ['ssh_common_args', 'sftp_extra_args', 'scp_extra_args', 'ssh_extra_args']:
for flag in ['ssh_common_args', 'docker_extra_args', 'sftp_extra_args', 'scp_extra_args', 'ssh_extra_args']:
setattr(self, flag, getattr(options,flag, ''))
# general flags (should we move out?)
@ -550,4 +555,3 @@ class PlayContext(Base):
variables[var_opt] = var_val
except AttributeError:
continue

View file

@ -106,7 +106,13 @@ class Connection(ConnectionBase):
def _get_docker_version(self):
cmd = [self.docker_cmd, 'version']
cmd = [self.docker_cmd]
if self._play_context.docker_extra_args:
cmd += self._play_context.docker_extra_args.split(' ')
cmd += ['version']
cmd_output = subprocess.check_output(cmd)
for line in cmd_output.split('\n'):
@ -144,7 +150,12 @@ class Connection(ConnectionBase):
version we are using, it will be provided to docker exec.
"""
local_cmd = [self.docker_cmd, 'exec']
local_cmd = [self.docker_cmd]
if self._play_context.docker_extra_args:
local_cmd += self._play_context.docker_extra_args.split(' ')
local_cmd += ['exec']
if self.remote_user is not None:
local_cmd += ['-u', self.remote_user]