docker: fixes & add username parameter.
This commit is contained in:
parent
823dea4bd0
commit
9d0949eb99
|
@ -467,10 +467,10 @@ Sudo
|
||||||
Docker
|
Docker
|
||||||
~~~~~~
|
~~~~~~
|
||||||
|
|
||||||
Docker support has received relatively little testing, expect increased
|
Docker support is fairly new, expect increased surprises for now.
|
||||||
probability of surprises for the time being.
|
|
||||||
|
|
||||||
* ``ansible_host``
|
* ``ansible_host``: Name of Docker container.
|
||||||
|
* ``ansible_user``: Name of user within the container to execute as.
|
||||||
|
|
||||||
|
|
||||||
Debugging
|
Debugging
|
||||||
|
|
|
@ -485,6 +485,7 @@ class Importer(object):
|
||||||
self._present = {'mitogen': [
|
self._present = {'mitogen': [
|
||||||
'compat',
|
'compat',
|
||||||
'debug',
|
'debug',
|
||||||
|
'docker',
|
||||||
'fakessh',
|
'fakessh',
|
||||||
'fork',
|
'fork',
|
||||||
'master',
|
'master',
|
||||||
|
|
|
@ -38,9 +38,12 @@ LOG = logging.getLogger(__name__)
|
||||||
class Stream(mitogen.parent.Stream):
|
class Stream(mitogen.parent.Stream):
|
||||||
container = None
|
container = None
|
||||||
image = None
|
image = None
|
||||||
|
username = None
|
||||||
docker_path = 'docker'
|
docker_path = 'docker'
|
||||||
|
|
||||||
def construct(self, container=None, image=None, docker_path=None, **kwargs):
|
def construct(self, container=None, image=None,
|
||||||
|
docker_path=None, username=None,
|
||||||
|
**kwargs):
|
||||||
assert container or image
|
assert container or image
|
||||||
super(Stream, self).construct(**kwargs)
|
super(Stream, self).construct(**kwargs)
|
||||||
if container:
|
if container:
|
||||||
|
@ -49,16 +52,22 @@ class Stream(mitogen.parent.Stream):
|
||||||
self.image = image
|
self.image = image
|
||||||
if docker_path:
|
if docker_path:
|
||||||
self.docker_path = docker_path
|
self.docker_path = docker_path
|
||||||
|
if username:
|
||||||
|
self.username = username
|
||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
super(Stream, self).connect()
|
super(Stream, self).connect()
|
||||||
self.name = 'docker.' + (self.container or self.image)
|
self.name = 'docker.' + (self.container or self.image)
|
||||||
|
|
||||||
def get_boot_command(self):
|
def get_boot_command(self):
|
||||||
|
args = ['--interactive']
|
||||||
|
if self.username:
|
||||||
|
args += ['--user=' + self.username]
|
||||||
|
|
||||||
bits = [self.docker_path]
|
bits = [self.docker_path]
|
||||||
if self.container:
|
if self.container:
|
||||||
bits += ['exec', '-i', self.container]
|
bits += ['exec'] + args + [self.container]
|
||||||
elif self.image:
|
elif self.image:
|
||||||
bits += ['run', '-i', '--rm', self.image]
|
bits += ['run'] + args + ['--rm', self.image]
|
||||||
bits += super(Stream, self).get_boot_command()
|
|
||||||
return bits
|
return bits + super(Stream, self).get_boot_command()
|
||||||
|
|
Loading…
Reference in New Issue