From 93ea131f306b135ce3821b792819da7de2a99707 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Fri, 24 Dec 2021 11:27:23 +0100 Subject: [PATCH] Get rid of distutils.spawn. (#257) --- changelogs/fragments/257-remove-distutils-spawn.yml | 2 ++ plugins/connection/docker.py | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/257-remove-distutils-spawn.yml diff --git a/changelogs/fragments/257-remove-distutils-spawn.yml b/changelogs/fragments/257-remove-distutils-spawn.yml new file mode 100644 index 000000000..a1845117e --- /dev/null +++ b/changelogs/fragments/257-remove-distutils-spawn.yml @@ -0,0 +1,2 @@ +bugfixes: + - "docker connection plugin - replace deprecated ``distutils.spawn.find_executable`` with Ansible's ``get_bin_path`` to find the ``docker`` executable (https://github.com/ansible-collections/community.docker/pull/257)." diff --git a/plugins/connection/docker.py b/plugins/connection/docker.py index 6289b987d..745e936ce 100644 --- a/plugins/connection/docker.py +++ b/plugins/connection/docker.py @@ -41,7 +41,6 @@ - name: ansible_docker_host ''' -import distutils.spawn import fcntl import os import os.path @@ -54,6 +53,7 @@ from ansible.compat import selectors from ansible.errors import AnsibleError, AnsibleFileNotFound from ansible.module_utils.six.moves import shlex_quote +from ansible.module_utils.common.process import get_bin_path from ansible.module_utils.common.text.converters import to_bytes, to_native, to_text from ansible.plugins.connection import ConnectionBase, BUFSIZE from ansible.utils.display import Display @@ -86,8 +86,9 @@ def __init__(self, play_context, new_stdin, *args, **kwargs): if 'docker_command' in kwargs: self.docker_cmd = kwargs['docker_command'] else: - self.docker_cmd = distutils.spawn.find_executable('docker') - if not self.docker_cmd: + try: + self.docker_cmd = get_bin_path('docker') + except ValueError: raise AnsibleError("docker command not found in PATH") docker_version = self._get_docker_version()