issue #150: ansible: add basic Docker support.

wip-fakessh-exit-status
David Wilson 7 years ago
parent b64e52b1fd
commit 4691ce0b95

@ -160,6 +160,18 @@ class Connection(ansible.plugins.connection.ConnectionBase):
})
)
def _connect_docker(self):
return mitogen.service.call(
self.parent,
ContextService.handle,
cast({
'method': 'docker',
'container': self._play_context.remote_addr,
'python_path': self.python_path,
'connect_timeout': self._play_context.timeout,
})
)
def _connect_sudo(self, via=None, python_path=None):
"""
Fetch a reference to a sudo Context matching the play context from
@ -212,8 +224,13 @@ class Connection(ansible.plugins.connection.ConnectionBase):
self.context = self._connect_sudo(python_path=sys.executable)
else:
self.context = self._connect_local()
else:
return
if self.original_transport == 'docker':
self.host = self._connect_docker()
elif self.original_transport == 'ssh':
self.host = self._connect_ssh()
if self._play_context.become:
self.context = self._connect_sudo(via=self.host)
else:

@ -78,7 +78,7 @@ def wrap_connection_loader__get(name, play_context, new_stdin):
an argument, so that it can emulate the original type.
"""
kwargs = {}
if name in ('ssh', 'local'):
if name in ('ssh', 'local', 'docker'):
kwargs['original_transport'] = name
name = 'mitogen'
return connection_loader__get(name, play_context, new_stdin, **kwargs)

@ -258,6 +258,15 @@ Sudo Variables
* ansible.cfg: timeout
Docker Variables
----------------
Note: Docker support is only intended for developer testing, it might disappear
entirely prior to a stable release.
* ansible_host
Chat on IRC
-----------

@ -61,6 +61,4 @@ class Stream(mitogen.parent.Stream):
elif self.image:
bits += ['run', '-i', '--rm', self.image]
bits += super(Stream, self).get_boot_command()
LOG.debug('Docker command line: %r', bits)
print bits
return bits

Loading…
Cancel
Save