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

lookup bitwarden field=notes resulting in KeyError #6617

Closed
1 task done
SupVar opened this issue Jun 2, 2023 · 5 comments · Fixed by #7061
Closed
1 task done

lookup bitwarden field=notes resulting in KeyError #6617

SupVar opened this issue Jun 2, 2023 · 5 comments · Fixed by #7061
Labels
bug This issue/PR relates to a bug lookup lookup plugin plugins plugin (any type) traceback

Comments

@SupVar
Copy link

SupVar commented Jun 2, 2023

Summary

When using the community.general.bitwarden lookup there is an error trying to lookup a secure note.

Playbook:

- debug:
    msg: >-
      "{{ lookup('community.general.bitwarden', 'secure note 2023', field='notes') }}"

Error:

fatal: [my.hostname.net]: FAILED! => {
    "msg": "An unhandled exception occurred while running the lookup plugin 'community.general.bitwarden'. Error was a <class 'KeyError'>, original message: 'fields'. 'fields'"
}

With debug:

exception during Jinja2 execution: Traceback (most recent call last):
  File "/opt/homebrew/Cellar/ansible/8.0.0/libexec/lib/python3.11/site-packages/ansible/template/__init__.py", line 831, in _lookup
    ran = instance.run(loop_terms, variables=self._available_variables, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/ansible/8.0.0/libexec/lib/python3.11/site-packages/ansible_collections/community/general/plugins/lookup/bitwarden.py", line 159, in run
    return [_bitwarden.get_field(field, term, search_field, collection_id) for term in terms]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/ansible/8.0.0/libexec/lib/python3.11/site-packages/ansible_collections/community/general/plugins/lookup/bitwarden.py", line 159, in <listcomp>
    return [_bitwarden.get_field(field, term, search_field, collection_id) for term in terms]
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/ansible/8.0.0/libexec/lib/python3.11/site-packages/ansible_collections/community/general/plugins/lookup/bitwarden.py", line 141, in get_field
    for custom_field in match['fields']:
                        ~~~~~^^^^^^^^^^
KeyError: 'fields'
fatal: [my.hostname.net]: FAILED! => {
    "msg": "An unhandled exception occurred while running the lookup plugin 'community.general.bitwarden'. Error was a <class 'KeyError'>, original message: 'fields'. 'fields'"
}

Same thing when trying to do the lookup by id:

- debug:
    msg: >-
      "{{ lookup('community.general.bitwarden', 'ba9f1125-e52a-4d4f-9b2b-af1c43a00bd6', search='id', field='notes') }}"

Issue Type

Bug Report

Component Name

bitwarden

Ansible Version

$ ansible --version
ansible [core 2.15.0]
  config file = /Users/sjoerd/.ansible.cfg
  configured module search path = ['/Users/name/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /opt/homebrew/Cellar/ansible/8.0.0/libexec/lib/python3.11/site-packages/ansible
  ansible collection location = /Users/name/.ansible/collections:/usr/share/ansible/collections
  executable location = /opt/homebrew/bin/ansible
  python version = 3.11.3 (main, Apr  7 2023, 20:13:31) [Clang 14.0.0 (clang-1400.0.29.202)] (/opt/homebrew/Cellar/ansible/8.0.0/libexec/bin/python3.11)
  jinja version = 3.1.2
  libyaml = True

Community.general Version

$ ansible-galaxy collection list community.general

# /opt/homebrew/Cellar/ansible/8.0.0/libexec/lib/python3.11/site-packages/ansible_collections
Collection        Version
----------------- -------
community.general 7.0.1

Configuration

$ ansible-config dump --only-changed

OS / Environment

Source: MacOS
Target: CentOS Stream 9

Steps to Reproduce

- debug:
    msg: >-
      "{{ lookup('community.general.bitwarden', 'secure note 2023', field='notes') }}"

Expected Results

Expected the contents of the secure not to be printed to the terminal

Actual Results

fatal: [my.hostname.net]: FAILED! => {
    "msg": "An unhandled exception occurred while running the lookup plugin 'community.general.bitwarden'. Error was a <class 'KeyError'>, original message: 'fields'. 'fields'"
}

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@ansibullbot
Copy link
Collaborator

Files identified in the description:

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

@ansibullbot
Copy link
Collaborator

cc @lungj
click here for bot help

@ansibullbot ansibullbot added bug This issue/PR relates to a bug lookup lookup plugin plugins plugin (any type) traceback labels Jun 2, 2023
@felixfontein
Copy link
Collaborator

CC @reverendj1 who worked on this in #5694 and might have an idea what happens here. I guess the obvious fix is to check whether 'fields' in match before looping over match['fields'], but maybe there's something more interesting/complex going on.

@SupVar
Copy link
Author

SupVar commented Jun 12, 2023

Playing with this, another branch for some of the main level keys fixes the original issue:

137a136,137
>         elif field in ['favorite', 'folderId', 'name', 'notes', 'organizationId', 'reprompt', 'revisionDate']:
>             return [match[field] for match in matches]

@simonLeary42
Copy link
Contributor

#7061

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug lookup lookup plugin plugins plugin (any type) traceback
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants