From 05f9fb4dd8b27415c1fd5376ca787829c46ea4c6 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Wed, 31 Oct 2018 12:12:54 +0000 Subject: [PATCH] issue #409: don't run kubectl test in <2.5. --- .../plugins/connection/mitogen_kubectl.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/ansible_mitogen/plugins/connection/mitogen_kubectl.py b/ansible_mitogen/plugins/connection/mitogen_kubectl.py index 5ffe3f7b..855b4ec0 100644 --- a/ansible_mitogen/plugins/connection/mitogen_kubectl.py +++ b/ansible_mitogen/plugins/connection/mitogen_kubectl.py @@ -31,7 +31,12 @@ from __future__ import absolute_import import os.path import sys -import ansible.plugins.connection.kubectl +try: + from ansible.plugins.connection import kubectl +except ImportError: + kubectl = None + +from ansible.errors import AnsibleConnectionFailure from ansible.module_utils.six import iteritems try: @@ -47,6 +52,16 @@ import ansible_mitogen.connection class Connection(ansible_mitogen.connection.Connection): transport = 'kubectl' + not_supported_msg = ( + 'The "mitogen_kubectl" plug-in requires a version of Ansible ' + 'that ships with the "kubectl" connection plug-in.' + ) + + def __init__(self, *args, **kwargs): + if kubectl is None: + raise AnsibleConnectionFailure(self.not_supported_msg) + super(Connection, self).__init__(*args, **kwargs) + def get_extra_args(self): parameters = [] for key, option in iteritems(ansible.plugins.connection.kubectl.CONNECTION_OPTIONS):