Repository: ansible-collections/community.general

Issue:
Get clean data from bitwarden
### Summary

Unless I am missing something, I think the ansible bitwarden module is useless: I can make ansible it retrieve passwords from my bitwarden vault and inject them in my desired config files, but it retrieves a json object... which means that when using this to fill in passwords it will use the format **['password']** instead of the **plain** password....  is there a way to tell the ansible module to ONLY get the password field content and not put it in a stupid json?

Thanks and regards

### Issue Type

Feature Idea

### Component Name

bitwarden

### Additional Information

<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)

```


### Code of Conduct

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


Discussion:
Files identified in the description:
* [`plugins/lookup/bitwarden.py`](https://github.com/ansible-collections/community.general/blob/main/plugins/lookup/bitwarden.py)

If these files are incorrect, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/devel/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @lungj
[click here for bot help](https://github.com/ansible/ansibullbot/blob/devel/ISSUE_HELP.md)
<!--- boilerplate: notify --->
I'm pretty sure the **lookup plugin** (this is not a module) supports what you want. You might want to write what you did to get the Python list serialization (JSON does not use single quotes).
@felixfontein  thanks for your answer. I use the lookup plugin this way, like the documentation suggests:

```yaml
my_password: "{{ lookup('community.general.bitwarden', 'my-bitwarden-object-id', search='id', field='password') }}"
```
For some reason the lookup always returns a list of all field matches, even if you use `search='id'`. What you can do is pass the result of the lookup through the `first` filter (https://jinja.palletsprojects.com/en/3.0.x/templates/#jinja-filters.first):
```yaml
my_password: "{{ lookup('community.general.bitwarden', 'my-bitwarden-object-id', search='id', field='password') | first }}"
```

Ok thanks, that works! I think it should be then necessary to put this in the official bitwarden documentation examples, it is misleading otherwise...
I've created #7727 to improve the docs. Please take a look whether you find the changes helpful.
That's great , thanks a lot for your efforts!

Resolving patch:
diff --git a/plugins/lookup/bitwarden.py b/plugins/lookup/bitwarden.py
--- a/plugins/lookup/bitwarden.py
+++ b/plugins/lookup/bitwarden.py
@@ -25,7 +25,10 @@
         type: list
         elements: str
       search:
-        description: Field to retrieve, for example V(name) or V(id).
+        description:
+          - Field to retrieve, for example V(name) or V(id).
+          - If set to V(id), only zero or one element can be returned.
+            Use the Jinja C(first) filter to get the only list element.
         type: str
         default: name
         version_added: 5.7.0
@@ -39,27 +42,27 @@
 """
 
 EXAMPLES = """
-- name: "Get 'password' from Bitwarden record named 'a_test'"
+- name: "Get 'password' from all Bitwarden records named 'a_test'"
   ansible.builtin.debug:
     msg: >-
       {{ lookup('community.general.bitwarden', 'a_test', field='password') }}
 
-- name: "Get 'password' from Bitwarden record with id 'bafba515-af11-47e6-abe3-af1200cd18b2'"
+- name: "Get 'password' from Bitwarden record with ID 'bafba515-af11-47e6-abe3-af1200cd18b2'"
   ansible.builtin.debug:
     msg: >-
-      {{ lookup('community.general.bitwarden', 'bafba515-af11-47e6-abe3-af1200cd18b2', search='id', field='password') }}
+      {{ lookup('community.general.bitwarden', 'bafba515-af11-47e6-abe3-af1200cd18b2', search='id', field='password') | first }}
 
-- name: "Get 'password' from Bitwarden record named 'a_test' from collection"
+- name: "Get 'password' from all Bitwarden records named 'a_test' from collection"
   ansible.builtin.debug:
     msg: >-
       {{ lookup('community.general.bitwarden', 'a_test', field='password', collection_id='bafba515-af11-47e6-abe3-af1200cd18b2') }}
 
-- name: "Get full Bitwarden record named 'a_test'"
+- name: "Get list of all full Bitwarden records named 'a_test'"
   ansible.builtin.debug:
     msg: >-
       {{ lookup('community.general.bitwarden', 'a_test') }}
 
-- name: "Get custom field 'api_key' from Bitwarden record named 'a_test'"
+- name: "Get custom field 'api_key' from all Bitwarden records named 'a_test'"
   ansible.builtin.debug:
     msg: >-
       {{ lookup('community.general.bitwarden', 'a_test', field='api_key') }}
@@ -67,9 +70,12 @@
 
 RETURN = """
   _raw:
-    description: List of requested field or JSON object of list of matches.
+    description:
+      - A one-element list that contains a list of requested fields or JSON objects of matches.
+      - If you use C(query), you get a list of lists. If you use C(lookup) without C(wantlist=true),
+        this always gets reduced to a list of field values or JSON objects.
     type: list
-    elements: raw
+    elements: list
 """
 
 from subprocess import Popen, PIPE


Test patch: