From 390affe2656fd96bfec22dbf425c40ceb46b909a Mon Sep 17 00:00:00 2001 From: Tim Small Date: Tue, 14 Nov 2023 15:24:51 +0000 Subject: [PATCH 1/3] lxd: Add lxc command execution debug statement. --- plugins/connection/lxd.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/connection/lxd.py b/plugins/connection/lxd.py index 4ad81be3998..6a84272809a 100644 --- a/plugins/connection/lxd.py +++ b/plugins/connection/lxd.py @@ -101,6 +101,8 @@ def exec_command(self, cmd, in_data=None, sudoable=True): 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,6 +112,8 @@ def exec_command(self, cmd, in_data=None, sudoable=True): 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()) From 69c82664173788908d1f3168da78f6a29944cf4d Mon Sep 17 00:00:00 2001 From: Tim Small Date: Tue, 14 Nov 2023 15:25:39 +0000 Subject: [PATCH 2/3] lxd: avoid false positives in "instance not found" detection Due to changes over time in the error message which lxd printed when an instance wasn't found, the detection logic in the lxd connection plugin matched any "not found" string. Unfortunately this also false triggered on other errors e.g. "/usr/bin/python3: not found" from the payload, giving a confusing error message "UNREACHABLE! ... instance not found" to the ansible user. --- .../fragments/lxd-instance-not-found-avoid-false-positives.yml | 2 ++ plugins/connection/lxd.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/lxd-instance-not-found-avoid-false-positives.yml 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 00000000000..02aed5b55a9 --- /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``." diff --git a/plugins/connection/lxd.py b/plugins/connection/lxd.py index 6a84272809a..93e1ab7a46b 100644 --- a/plugins/connection/lxd.py +++ b/plugins/connection/lxd.py @@ -117,7 +117,7 @@ def exec_command(self, cmd, in_data=None, sudoable=True): 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 From 70a25cffd681e67495ff66272c9d02142498f80c Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Fri, 1 Dec 2023 07:38:57 +0100 Subject: [PATCH 3/3] Update changelog fragment. --- .../fragments/lxd-instance-not-found-avoid-false-positives.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelogs/fragments/lxd-instance-not-found-avoid-false-positives.yml b/changelogs/fragments/lxd-instance-not-found-avoid-false-positives.yml index 02aed5b55a9..03ac8ee01bb 100644 --- a/changelogs/fragments/lxd-instance-not-found-avoid-false-positives.yml +++ b/changelogs/fragments/lxd-instance-not-found-avoid-false-positives.yml @@ -1,2 +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``." + - "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)."