Repository: ansible-collections/community.general

Issue:
tss lookup plugin fails in 3.5.0 release
### Summary

Following the release of community.general 3.5.0, the thrycotic secret server lookup plugin is producing an error.  The error is no longer present if reverted to 3.4.0 


Error:
 "msg": "An unhandled exception occurred while running the lookup plugin 'vars'. Error was a <class 'ansible.errors.AnsibleError'>, original message: An unhandled exception occurred while templating '{{ lookup('community.general.tss', 3204) }}'. Error was a <class 'ansible.errors.AnsibleError'>, original message: An unhandled exception occurred while running the lookup plugin 'community.general.tss'. Error was a <class 'ansible.errors.AnsibleError'>, original message: python-tss-sdk must be installed to use this plugin",


### Issue Type

Bug Report

### Component Name

tss lookup plugin

### Ansible Version

```console (paste below)
$ ansible --version

```
2.9.23

### Configuration

```console (paste below)
$ ansible-config dump --only-changed

```


### OS / Environment

RHEL 7, Ansible Tower 3.8.2

### Steps to Reproduce

<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)

```
 lookup('community.general.tss', 3204)

### Expected Results

The secret is retrieved

### Actual Results

```console (paste below)

```
"msg": "An unhandled exception occurred while running the lookup plugin 'vars'. Error was a <class 'ansible.errors.AnsibleError'>, original message: An unhandled exception occurred while templating '{{ lookup('community.general.tss', 3204) }}'. Error was a <class 'ansible.errors.AnsibleError'>, original message: An unhandled exception occurred while running the lookup plugin 'community.general.tss'. Error was a <class 'ansible.errors.AnsibleError'>, original message: python-tss-sdk must be installed to use this plugin",

### Code of Conduct

- [X] I agree to follow the Ansible Code of Conduct


Discussion:
!component =plugins/lookup/tss.py
This could be related to #3139.

CC @EndlessTrax @amigus
@cschroeder512 When you revert back are you doing so on the same machine? The error suggests you don't have the `python-tss-sdk` installed if it's a different machine. 

If you're in the same machine, what version of the sdk are you running? (so I can try reproduce the error) 


@EndlessTrax 
python-tss-sdk version 0.0.5

This plugin broke on 2 servers, both ansible tower servers, where the sdk is installed in a venv, and the playbooks are using the venv.  there have been no modifications to the venv or to the plugin, other than the update to the community.general collection.  The plugin had been working fine for months, up until today.

thanks
@cschroeder512 @felixfontein 

Okay, I've isolated the issue. It appears, and I do not know why, that **v0.0.5** doesn't have the builtin `__version__`. So the import is failing. This seems only to be an issue with that version, **0.0.6** and **1.0.0** have the expected builtin `__version__`.

I'm working on the fix now to make the plugin backwards compatible. And will be making a PR soon. But I would also recommend you look at upgrading your SDK anyway in the near future, as we'll be adding support for Domain and Token authentication, too. That will require at least v1.0.0
excellent, thanks @EndlessTrax 

Resolving patch:
diff --git a/plugins/lookup/tss.py b/plugins/lookup/tss.py
--- a/plugins/lookup/tss.py
+++ b/plugins/lookup/tss.py
@@ -118,15 +118,23 @@
 sdk_is_missing = False
 
 try:
-    from thycotic import __version__ as sdk_version
-    from thycotic.secrets.server import (
-        SecretServer,
-        SecretServerError,
-        PasswordGrantAuthorizer,
-    )
+    from thycotic.secrets.server import SecretServer, SecretServerError
 except ImportError:
     sdk_is_missing = True
 
+# Added for backwards compatability - See issue #3192
+# https://github.com/ansible-collections/community.general/issues/3192
+try:
+    from thycotic import __version__ as sdk_version
+except ImportError:
+    sdk_version = "0.0.5"
+
+try:
+    from thycotic.secrets.server import PasswordGrantAuthorizer
+    sdK_version_below_v1 = False
+except ImportError:
+    sdK_version_below_v1 = True
+
 from ansible.utils.display import Display
 from ansible.plugins.lookup import LookupBase
 
@@ -138,9 +146,13 @@ class LookupModule(LookupBase):
     @staticmethod
     def Client(server_parameters):
 
-        if LooseVersion(sdk_version) < LooseVersion('1.0.0'):
+        if LooseVersion(sdk_version) < LooseVersion('1.0.0') or sdK_version_below_v1:
             return SecretServer(**server_parameters)
         else:
+            # The Password Authorizer became available in v1.0.0 and beyond.
+            # Import only if sdk_version requires it.
+            # from thycotic.secrets.server import PasswordGrantAuthorizer
+
             authorizer = PasswordGrantAuthorizer(
                 server_parameters["base_url"],
                 server_parameters["username"],


Test patch: