mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-27 18:50:21 -07:00
Merge pull request #13425 from ThomasSteinbach/docker_remote_connection
Allow setup of docker remote connections
This commit is contained in:
commit
fda3408db3
2 changed files with 19 additions and 4 deletions
|
@ -65,6 +65,7 @@ MAGIC_VARIABLE_MAPPING = dict(
|
||||||
become_exe = ('ansible_become_exe',),
|
become_exe = ('ansible_become_exe',),
|
||||||
become_flags = ('ansible_become_flags',),
|
become_flags = ('ansible_become_flags',),
|
||||||
ssh_common_args = ('ansible_ssh_common_args',),
|
ssh_common_args = ('ansible_ssh_common_args',),
|
||||||
|
docker_extra_args= ('ansible_docker_extra_args',),
|
||||||
sftp_extra_args = ('ansible_sftp_extra_args',),
|
sftp_extra_args = ('ansible_sftp_extra_args',),
|
||||||
scp_extra_args = ('ansible_scp_extra_args',),
|
scp_extra_args = ('ansible_scp_extra_args',),
|
||||||
ssh_extra_args = ('ansible_ssh_extra_args',),
|
ssh_extra_args = ('ansible_ssh_extra_args',),
|
||||||
|
@ -121,6 +122,7 @@ TASK_ATTRIBUTE_OVERRIDES = (
|
||||||
'become_pass',
|
'become_pass',
|
||||||
'become_method',
|
'become_method',
|
||||||
'connection',
|
'connection',
|
||||||
|
'docker_extra_args',
|
||||||
'delegate_to',
|
'delegate_to',
|
||||||
'no_log',
|
'no_log',
|
||||||
'remote_user',
|
'remote_user',
|
||||||
|
@ -128,6 +130,7 @@ TASK_ATTRIBUTE_OVERRIDES = (
|
||||||
|
|
||||||
RESET_VARS = (
|
RESET_VARS = (
|
||||||
'ansible_connection',
|
'ansible_connection',
|
||||||
|
'ansible_docker_extra_args',
|
||||||
'ansible_ssh_host',
|
'ansible_ssh_host',
|
||||||
'ansible_ssh_pass',
|
'ansible_ssh_pass',
|
||||||
'ansible_ssh_port',
|
'ansible_ssh_port',
|
||||||
|
@ -149,6 +152,7 @@ class PlayContext(Base):
|
||||||
|
|
||||||
# connection fields, some are inherited from Base:
|
# connection fields, some are inherited from Base:
|
||||||
# (connection, port, remote_user, environment, no_log)
|
# (connection, port, remote_user, environment, no_log)
|
||||||
|
_docker_extra_args = FieldAttribute(isa='string')
|
||||||
_remote_addr = FieldAttribute(isa='string')
|
_remote_addr = FieldAttribute(isa='string')
|
||||||
_password = FieldAttribute(isa='string')
|
_password = FieldAttribute(isa='string')
|
||||||
_private_key_file = FieldAttribute(isa='string', default=C.DEFAULT_PRIVATE_KEY_FILE)
|
_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
|
options specified by the user on the command line. These have a
|
||||||
lower precedence than those set on the play or host.
|
lower precedence than those set on the play or host.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
# privilege escalation
|
# privilege escalation
|
||||||
self.become = options.become
|
self.become = options.become
|
||||||
self.become_method = options.become_method
|
self.become_method = options.become_method
|
||||||
|
@ -261,7 +266,7 @@ class PlayContext(Base):
|
||||||
self.check_mode = boolean(options.check)
|
self.check_mode = boolean(options.check)
|
||||||
|
|
||||||
# get ssh options FIXME: make these common to all connections
|
# 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, ''))
|
setattr(self, flag, getattr(options,flag, ''))
|
||||||
|
|
||||||
# general flags (should we move out?)
|
# general flags (should we move out?)
|
||||||
|
@ -550,4 +555,3 @@ class PlayContext(Base):
|
||||||
variables[var_opt] = var_val
|
variables[var_opt] = var_val
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
|
@ -106,7 +106,13 @@ class Connection(ConnectionBase):
|
||||||
|
|
||||||
def _get_docker_version(self):
|
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)
|
cmd_output = subprocess.check_output(cmd)
|
||||||
|
|
||||||
for line in cmd_output.split('\n'):
|
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.
|
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:
|
if self.remote_user is not None:
|
||||||
local_cmd += ['-u', self.remote_user]
|
local_cmd += ['-u', self.remote_user]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue