From 39e71bb7cef4b9166f0674b2ff3949cc26f07731 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Mon, 8 Oct 2018 19:10:27 +0530 Subject: [PATCH] Plugin: check if executable exists in local connection (#46201) This fix checks if executable exists in local connection specified using ANSIBLE_EXECUTABLE variable. Signed-off-by: Abhijeet Kasurde --- lib/ansible/plugins/connection/local.py | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/lib/ansible/plugins/connection/local.py b/lib/ansible/plugins/connection/local.py index be0bfaae25..e4ea3f5ac0 100644 --- a/lib/ansible/plugins/connection/local.py +++ b/lib/ansible/plugins/connection/local.py @@ -1,20 +1,7 @@ # (c) 2012, Michael DeHaan # (c) 2015, 2017 Toshio Kuratomi -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + from __future__ import (absolute_import, division, print_function) __metaclass__ = type @@ -78,6 +65,10 @@ class Connection(ConnectionBase): executable = C.DEFAULT_EXECUTABLE.split()[0] if C.DEFAULT_EXECUTABLE else None + if not os.path.exists(to_bytes(executable, errors='surrogate_or_strict')): + raise AnsibleError("failed to find the executable specified %s." + " Please verify if the executable exists and re-try." % executable) + display.vvv(u"EXEC {0}".format(to_text(cmd)), host=self._play_context.remote_addr) display.debug("opening command with Popen()") @@ -152,7 +143,7 @@ class Connection(ConnectionBase): raise AnsibleError("failed to transfer file to {0}: {1}".format(to_native(out_path), to_native(e))) def fetch_file(self, in_path, out_path): - ''' fetch a file from local to local -- for copatibility ''' + ''' fetch a file from local to local -- for compatibility ''' super(Connection, self).fetch_file(in_path, out_path)