ansible-collections / community.general

Ansible Community General Collection
https://galaxy.ansible.com/ui/repo/published/community/general/
GNU General Public License v3.0
833 stars 1.53k forks source link

Passwordstore lookup creates subkeys even when create==false and subkey does not exist #9105

Open mluzarreta opened 2 weeks ago

mluzarreta commented 2 weeks ago

Summary

When using passwordstore lookup to retrieve subkeys, if the subkey is missing, the lookup will create it even if create == false This bug has been introduced with https://github.com/ansible-collections/community.general/pull/8952

Issue Type

Bug Report

Component Name

passwordstore lookup

Ansible Version

$ ansible --version
ansible [core 2.18.0]
  config file = None
  configured module search path = ['/home/manu/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.12/site-packages/ansible
  ansible collection location = /home/manu/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.12.7 (main, Oct  1 2024, 11:15:50) [GCC 14.2.1 20240910] (/usr/bin/python)
  jinja version = 3.1.4
  libyaml = True

Community.general Version

$ ansible-galaxy collection list community.general

# /home/manu/.ansible/collections/ansible_collections
Collection        Version
----------------- -------
community.general 10.0.0

Configuration

$ ansible-config dump --only-changed
CONFIG_FILE() = None
EDITOR(env: EDITOR) = hx

OS / Environment

Archlinux

Steps to Reproduce

Initial state : a password named example/test already exists but NO subkey

$ pass example/test
.vzaq:,cCvr_Lxeu
lookup_pass: First generated by ansible on 07/11/2024 11:34:53

We try to retrieve a non-existent subkey

ansible -m debug -i localhost, -a "msg={{ lookup('community.general.passwordstore', 'example/test', subkey='foo') }}" localhost

Expected Results

With missing_subkey: empty

ansible -m debug -i localhost, -a "msg={{ lookup('community.general.passwordstore', 'example/test', subkey='foo') }}" localhost
localhost | SUCCESS => {
    "msg": ""
}

Actual Results

Subkey is created even when create == false

ansible -m debug -i localhost, -a "msg={{ lookup('community.general.passwordstore', 'example/test', subkey='foo') }}" localhost
localhost | SUCCESS => {
    "msg": "IJdLJcEoPGJ7dCX1"
}

Code of Conduct

ansibullbot commented 2 weeks ago

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

felixfontein commented 2 weeks ago

!component =plugins/lookup/passwordstore.py

ansibullbot commented 2 weeks ago

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