mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-21 12:20:21 -07:00
incus_connection: Improve error handling (#10349)
Related to #10344 This tweaks the error handling logic to work with more versions of Incus as well as catching some of the project and instance access errors. The full context (instance name, project name and remote name) is now included so that the user can easily diagnose access problems. Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
This commit is contained in:
parent
7a4448d45c
commit
4195cbb364
2 changed files with 30 additions and 4 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- incus connection plugin - fix error handling to return more useful Ansible errors to the user (https://github.com/ansible-collections/community.general/issues/10344, https://github.com/ansible-collections/community.general/pull/10349).
|
|
@ -155,11 +155,35 @@ class Connection(ConnectionBase):
|
||||||
stdout = to_text(stdout)
|
stdout = to_text(stdout)
|
||||||
stderr = to_text(stderr)
|
stderr = to_text(stderr)
|
||||||
|
|
||||||
if stderr == "Error: Instance is not running.\n":
|
if stderr.startswith("Error: ") and stderr.rstrip().endswith(
|
||||||
raise AnsibleConnectionFailure(f"instance not running: {self._instance()}")
|
": Instance is not running"
|
||||||
|
):
|
||||||
|
raise AnsibleConnectionFailure(
|
||||||
|
f"instance not running: {self._instance()} (remote={self.get_option('remote')}, project={self.get_option('project')})"
|
||||||
|
)
|
||||||
|
|
||||||
if stderr == "Error: Instance not found\n":
|
if stderr.startswith("Error: ") and stderr.rstrip().endswith(
|
||||||
raise AnsibleConnectionFailure(f"instance not found: {self._instance()}")
|
": Instance not found"
|
||||||
|
):
|
||||||
|
raise AnsibleConnectionFailure(
|
||||||
|
f"instance not found: {self._instance()} (remote={self.get_option('remote')}, project={self.get_option('project')})"
|
||||||
|
)
|
||||||
|
|
||||||
|
if (
|
||||||
|
stderr.startswith("Error: ")
|
||||||
|
and ": User does not have permission " in stderr
|
||||||
|
):
|
||||||
|
raise AnsibleConnectionFailure(
|
||||||
|
f"instance access denied: {self._instance()} (remote={self.get_option('remote')}, project={self.get_option('project')})"
|
||||||
|
)
|
||||||
|
|
||||||
|
if (
|
||||||
|
stderr.startswith("Error: ")
|
||||||
|
and ": User does not have entitlement " in stderr
|
||||||
|
):
|
||||||
|
raise AnsibleConnectionFailure(
|
||||||
|
f"instance access denied: {self._instance()} (remote={self.get_option('remote')}, project={self.get_option('project')})"
|
||||||
|
)
|
||||||
|
|
||||||
return process.returncode, stdout, stderr
|
return process.returncode, stdout, stderr
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue