diff --git a/changelogs/fragments/lxd-instance-not-found-avoid-false-positives.yml b/changelogs/fragments/lxd-instance-not-found-avoid-false-positives.yml new file mode 100644 index 0000000000..03ac8ee01b --- /dev/null +++ b/changelogs/fragments/lxd-instance-not-found-avoid-false-positives.yml @@ -0,0 +1,2 @@ +minor_changes: + - "lxd connection plugin - tighten the detection logic for lxd ``Instance not found`` errors, to avoid false detection on unrelated errors such as ``/usr/bin/python3: not found`` (https://github.com/ansible-collections/community.general/pull/7521)." diff --git a/plugins/connection/lxd.py b/plugins/connection/lxd.py index 4ad81be399..93e1ab7a46 100644 --- a/plugins/connection/lxd.py +++ b/plugins/connection/lxd.py @@ -101,6 +101,8 @@ class Connection(ConnectionBase): self.get_option("executable"), "-c", cmd ]) + self._display.vvvvv(u"EXEC {0}".format(local_cmd), host=self._host()) + local_cmd = [to_bytes(i, errors='surrogate_or_strict') for i in local_cmd] in_data = to_bytes(in_data, errors='surrogate_or_strict', nonstring='passthru') @@ -110,10 +112,12 @@ class Connection(ConnectionBase): stdout = to_text(stdout) stderr = to_text(stderr) + self._display.vvvvv(u"EXEC lxc output: {0} {1}".format(stdout, stderr), host=self._host()) + if "is not running" in stderr: raise AnsibleConnectionFailure("instance not running: %s" % self._host()) - if "not found" in stderr: + if stderr.strip() == "Error: Instance not found" or stderr.strip() == "error: not found": raise AnsibleConnectionFailure("instance not found: %s" % self._host()) return process.returncode, stdout, stderr