diff --git a/ansible/library/kolla_container_facts.py b/ansible/library/kolla_container_facts.py index a2c73009d7..dcdd931e94 100644 --- a/ansible/library/kolla_container_facts.py +++ b/ansible/library/kolla_container_facts.py @@ -52,6 +52,13 @@ EXAMPLES = ''' import docker +def get_docker_client(): + try: + return docker.Client + except AttributeError: + return docker.APIClient + + def main(): argument_spec = dict( name=dict(required=False, type='list', default=[]), @@ -61,7 +68,7 @@ def main(): module = AnsibleModule(argument_spec=argument_spec) results = dict(changed=False, _containers=[]) - client = docker.Client(version=module.params.get('api_version')) + client = get_docker_client()(version=module.params.get('api_version')) containers = client.containers() names = module.params.get('name') if names and not isinstance(names, list): diff --git a/ansible/library/kolla_docker.py b/ansible/library/kolla_docker.py index e41c9b740c..539242676a 100644 --- a/ansible/library/kolla_docker.py +++ b/ansible/library/kolla_docker.py @@ -197,6 +197,13 @@ import traceback import docker +def get_docker_client(): + try: + return docker.Client + except AttributeError: + return docker.APIClient + + class DockerWorker(object): def __init__(self, module): @@ -211,7 +218,7 @@ class DockerWorker(object): 'version': self.params.get('api_version') } - self.dc = docker.Client(**options) + self.dc = get_docker_client()(**options) def generate_tls(self): tls = {'verify': self.params.get('tls_verify')} diff --git a/ansible/library/kolla_toolbox.py b/ansible/library/kolla_toolbox.py index 458665f35a..8725434008 100644 --- a/ansible/library/kolla_toolbox.py +++ b/ansible/library/kolla_toolbox.py @@ -102,6 +102,13 @@ def gen_commandline(params): return command +def get_docker_client(): + try: + return docker.Client + except AttributeError: + return docker.APIClient + + def main(): specs = dict( module_name=dict(type='str'), @@ -109,7 +116,7 @@ def main(): module_extra_vars=dict(type='json') ) module = AnsibleModule(argument_spec=specs, bypass_checks=True) - client = docker.Client() + client = get_docker_client()() command_line = gen_commandline(module.params) kolla_toolbox = client.containers(filters=dict(name='kolla_toolbox', status='running'))