Commit 4691ce0b authored by David Wilson's avatar David Wilson

issue #150: ansible: add basic Docker support.

parent b64e52b1
...@@ -160,6 +160,18 @@ class Connection(ansible.plugins.connection.ConnectionBase): ...@@ -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): def _connect_sudo(self, via=None, python_path=None):
""" """
Fetch a reference to a sudo Context matching the play context from Fetch a reference to a sudo Context matching the play context from
...@@ -212,12 +224,17 @@ class Connection(ansible.plugins.connection.ConnectionBase): ...@@ -212,12 +224,17 @@ class Connection(ansible.plugins.connection.ConnectionBase):
self.context = self._connect_sudo(python_path=sys.executable) self.context = self._connect_sudo(python_path=sys.executable)
else: else:
self.context = self._connect_local() 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() self.host = self._connect_ssh()
if self._play_context.become:
self.context = self._connect_sudo(via=self.host) if self._play_context.become:
else: self.context = self._connect_sudo(via=self.host)
self.context = self.host else:
self.context = self.host
def close(self): def close(self):
""" """
......
...@@ -78,7 +78,7 @@ def wrap_connection_loader__get(name, play_context, new_stdin): ...@@ -78,7 +78,7 @@ def wrap_connection_loader__get(name, play_context, new_stdin):
an argument, so that it can emulate the original type. an argument, so that it can emulate the original type.
""" """
kwargs = {} kwargs = {}
if name in ('ssh', 'local'): if name in ('ssh', 'local', 'docker'):
kwargs['original_transport'] = name kwargs['original_transport'] = name
name = 'mitogen' name = 'mitogen'
return connection_loader__get(name, play_context, new_stdin, **kwargs) return connection_loader__get(name, play_context, new_stdin, **kwargs)
......
...@@ -258,6 +258,15 @@ Sudo Variables ...@@ -258,6 +258,15 @@ Sudo Variables
* ansible.cfg: timeout * 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 Chat on IRC
----------- -----------
......
...@@ -61,6 +61,4 @@ class Stream(mitogen.parent.Stream): ...@@ -61,6 +61,4 @@ class Stream(mitogen.parent.Stream):
elif self.image: elif self.image:
bits += ['run', '-i', '--rm', self.image] bits += ['run', '-i', '--rm', self.image]
bits += super(Stream, self).get_boot_command() bits += super(Stream, self).get_boot_command()
LOG.debug('Docker command line: %r', bits)
print bits
return bits return bits
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment