diff --git a/ansible/shell_plugins/docker.py b/ansible/shell_plugins/docker.py index 5977ae518f..022eed32c3 100644 --- a/ansible/shell_plugins/docker.py +++ b/ansible/shell_plugins/docker.py @@ -1,6 +1,17 @@ from __future__ import (absolute_import, division) __metaclass__ = type +DOCUMENTATION = ''' +name: docker +plugin_type: shell +short_description: "docker shell plugin" +version_added: historical +description: + - This module allows you to execute commands directly in docker on the remote host +extends_documentation_fragment: + - shell_common +''' + import os import re import pipes @@ -29,7 +40,24 @@ def join_path(self, *args): return super(ShellModule, self).join_path(*args) - def build_module_command(self, env_string, shebang, cmd, arg_path=None, rm_tmp=None): + def remove(self, path, recurse=False): + argv = self.get_option('ansible_python_interpreter').split() + assert(argv[0] == 'docker') + assert(argv[1] == 'exec') + opts, args = getopt.getopt(argv[2:], 'i') + self.container_name = args[0] + + remove_files_on_host_cmd = super(ShellModule, self).remove(path, recurse) + + cmd = remove_files_on_host_cmd + "; docker exec -i " + cmd += self.container_name + " rm -f " + if recurse: + cmd += '-r ' + cmd += " ".join(self.dtemps) + + return cmd + + def build_module_command(self, env_string, shebang, cmd, arg_path=None): # assert(self.container_name) argv = shlex.split(shebang.replace("#!", "")) assert(argv[0] == 'docker') @@ -51,13 +79,7 @@ def build_module_command(self, env_string, shebang, cmd, arg_path=None, rm_tmp=N pre = ''.join('docker exec {1} mkdir -p {0}; docker cp {0}/. {1}:{0}; ' .format(dtemp, self.container_name) for dtemp in self.dtemps) - if rm_tmp: - post = ''.join('docker exec {1} rm -rf {0}; ' - .format(dtemp, self.container_name) for dtemp in self.dtemps) - else: - post = '' - - return pre + super(ShellModule, self).build_module_command('', shebang_env, cmd, arg_path, rm_tmp) + '; ' + post + return pre + super(ShellModule, self).build_module_command('', shebang_env, cmd, arg_path) def checksum(self, path, python_interp): """