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

[PR #8952/24f2b980 backport][stable-9] passwordstore: Support subkey creation and update #8996

Closed patchback[bot] closed 1 month ago

patchback[bot] commented 1 month ago

This is a backport of PR #8952 as merged into main (24f2b980b79cedd199959a29cbfd022cd5791076).

SUMMARY

passwordstore lookup - Add the ability to create and update subkeys in password files.

ISSUE TYPE
COMPONENT NAME

passwordstore lookup

ADDITIONAL INFORMATION

Here some command lines to illustrate the feature:

# Create a new 'foo' subkey, in an new password store file (in this case, main password is empty)
❯ ansible -m debug -i localhost, -a "msg={{ lookup('community.general.passwordstore', 'example/test', create=true, subkey='foo') }}" localhost
localhost | SUCCESS => {
    "msg": "u6V31gj3d0i3lLbO"
}
# Replace the 'foo' subkey and keep a backup trace in the password file
❯ ansible -m debug -i localhost, -a "msg={{ lookup('community.general.passwordstore', 'example/test', create=true, subkey='foo', overwrite=true, backup=true) }}
" localhost
localhost | SUCCESS => {
    "msg": "8jRMhmn9bE-Ra:Yh"
}
# Replace the main password
❯ ansible -m debug -i localhost, -a "msg={{ lookup('community.general.passwordstore', 'example/test', create=true, overwrite=true) }}" localhost
localhost | SUCCESS => {
    "msg": "Mjol:uhPxIiGcchM"
}
# Display the content of the password file
❯ pass example/test 
Mjol:uhPxIiGcchM

foo: 8jRMhmn9bE-Ra:Yh
lookup_pass: First generated by ansible on 01/10/2024 11:37:25
lookup_pass: old subkey password foo was u6V31gj3d0i3lLbO (Updated on 01/10/2024 11:38:03)