Note
This lookup plugin is part of the community.general collection (version 10.7.3).
You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.
To install it, use: ansible-galaxy collection install community.general.
To use it in a playbook, specify: community.general.passwordstore.
auto-expand-secmem to ~/.gnupg/gpg-agent.conf. Where this is not possible, consider using lock=readwrite instead.Parameter | Comments |
|---|---|
Terms string / required | Query key. |
This describes keyword parameters of the lookup. These are the values key1=value1, key2=value2 and so on in the following examples: lookup('community.general.passwordstore', key1=value1, key2=value2, ...) and query('community.general.passwordstore', key1=value1, key2=value2, ...)
Parameter | Comments |
|---|---|
backend string added in community.general 5.2.0 | Specify which backend to use. Defaults to
Choices:
Configuration:
|
backup boolean | Used with Choices:
|
create boolean | Create the password or the subkey if it does not already exist. Takes precedence over Choices:
|
directory path | The directory of the password store. If If Configuration:
|
length integer | The length of the generated password. Default: |
lock string added in community.general 4.5.0 | How to synchronize operations. The default of
Choices:
Configuration:
|
locktimeout string added in community.general 4.5.0 | Lock timeout applied when Time with a unit suffix, Correlates with Default: Configuration:
|
missing string added in community.general 3.1.0 | List of preference about what to do if the password file is missing. If If set to If set to If set to Choices:
|
missing_subkey string added in community.general 8.6.0 | Preference about what to do if the password subkey is missing. If set to If set to Choices:
Configuration:
|
nosymbols boolean | Use alphanumeric characters. Choices:
|
overwrite boolean | Overwrite the password or the subkey if it does already exist. Choices:
|
preserve boolean added in community.general 8.1.0 | Include the old (edited) password inside the pass file. Choices:
|
returnall boolean | Return all the content of the password, not only the first line. Choices:
|
subkey string | By default return a specific subkey of the password. When set to With Default: |
timestamp boolean added in community.general 8.1.0 | Add the password generation information to the end of the file. Choices:
|
umask string added in community.general 1.3.0 | Sets the umask for the created Note pass’ default value is Configuration:
|
userpass string | Specify a password to save, instead of a generated one. |
Note
Configuration entries listed above for each entry type (Ansible variable, environment variable, and so on) have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up. The entry types are also ordered by precedence from low to high priority order. For example, an ansible.cfg entry (further up in the list) is overwritten by an Ansible variable (further down in the list).
Note
lookup('community.general.passwordstore', term1, term2, key1=value1, key2=value2) and query('community.general.passwordstore', term1, term2, key1=value1, key2=value2)
ansible.cfg: |
[passwordstore_lookup]
lock=readwrite
locktimeout=45s
missing_subkey=warn
tasks.yml: |-
---
# Debug is used for examples, BAD IDEA to show passwords on screen
- name: Basic lookup. Fails if example/test does not exist
ansible.builtin.debug:
msg: "{{ lookup('community.general.passwordstore', 'example/test')}}"
- name: Basic lookup. Warns if example/test does not exist and returns empty string
ansible.builtin.debug:
msg: "{{ lookup('community.general.passwordstore', 'example/test', missing='warn')}}"
- name: Create pass with random 16 character password. If password exists just give the password
ansible.builtin.debug:
var: mypassword
vars:
mypassword: "{{ lookup('community.general.passwordstore', 'example/test', create=true)}}"
- name: Create pass with random 16 character password. If password exists just give the password
ansible.builtin.debug:
var: mypassword
vars:
mypassword: "{{ lookup('community.general.passwordstore', 'example/test', missing='create')}}"
- name: >-
Create a random 16 character password in a subkey. If the password file already exists, just add the subkey in it.
If the subkey exists, returns it
ansible.builtin.debug:
msg: "{{ lookup('community.general.passwordstore', 'example/test', create=true, subkey='foo') }}"
- name: >-
Create a random 16 character password in a subkey. Overwrite if it already exists and backup the old one.
ansible.builtin.debug:
msg: "{{ lookup('community.general.passwordstore', 'example/test', create=true, subkey='user', overwrite=true, backup=true) }}"
- name: Prints 'abc' if example/test does not exist, just give the password otherwise
ansible.builtin.debug:
var: mypassword
vars:
mypassword: >-
{{ lookup('community.general.passwordstore', 'example/test', missing='empty')
| default('abc', true) }}
- name: Different size password
ansible.builtin.debug:
msg: "{{ lookup('community.general.passwordstore', 'example/test', create=true, length=42)}}"
- name: >-
Create password and overwrite the password if it exists.
As a bonus, this module includes the old password inside the pass file
ansible.builtin.debug:
msg: "{{ lookup('community.general.passwordstore', 'example/test', create=true, overwrite=true)}}"
- name: Create an alphanumeric password
ansible.builtin.debug:
msg: "{{ lookup('community.general.passwordstore', 'example/test', create=true, nosymbols=true) }}"
- name: Return the value for user in the KV pair user, username
ansible.builtin.debug:
msg: "{{ lookup('community.general.passwordstore', 'example/test', subkey='user')}}"
- name: Return the entire password file content
ansible.builtin.set_fact:
passfilecontent: "{{ lookup('community.general.passwordstore', 'example/test', returnall=true)}}"
Key | Description |
|---|---|
Return value list / elements=string | A password. Returned: success |
© 2012–2018 Michael DeHaan
© 2018–2025 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/latest/collections/community/general/passwordstore_lookup.html