Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove distutils from connection plugin #456

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/456-replace-distutils.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- kubectl.py - replace distutils.spawn.find_executable with shutil.which in the kubectl connection plugin (https://github.com/ansible-collections/kubernetes.core/pull/456).
13 changes: 4 additions & 9 deletions plugins/connection/kubectl.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@
aliases: [ kubectl_verify_ssl ]
"""

import distutils.spawn
import os
import os.path
import shutil
import subprocess

from ansible.parsing.yaml.loader import AnsibleLoader
Expand Down Expand Up @@ -219,14 +219,9 @@ def __init__(self, play_context, new_stdin, *args, **kwargs):
# Note: kubectl runs commands as the user that started the container.
# It is impossible to set the remote user for a kubectl connection.
cmd_arg = "{0}_command".format(self.transport)
if cmd_arg in kwargs:
self.transport_cmd = kwargs[cmd_arg]
else:
self.transport_cmd = distutils.spawn.find_executable(self.transport)
if not self.transport_cmd:
raise AnsibleError(
"{0} command not found in PATH".format(self.transport)
)
self.transport_cmd = kwargs.get(cmd_arg, shutil.which(self.transport))
if not self.transport_cmd:
raise AnsibleError("{0} command not found in PATH".format(self.transport))

def _build_exec_cmd(self, cmd):
"""Build the local kubectl exec command to run cmd on remote_host"""
Expand Down