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

Lxd instance not found fix false positives #7521

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
Original file line number Diff line number Diff line change
@@ -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)."
6 changes: 5 additions & 1 deletion plugins/connection/lxd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -110,10 +112,12 @@ 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())

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
Expand Down