community.general.passwordstore 查询 – 使用 passwordstore.org 的 pass 工具管理密码
注意
此查询插件是 community.general 集合 (版本 10.1.0) 的一部分。
如果您使用的是 ansible
包,则可能已经安装了此集合。它不包含在 ansible-core
中。要检查它是否已安装,请运行 ansible-galaxy collection list
。
要安装它,请使用: ansible-galaxy collection install community.general
。
要在剧本中使用它,请指定: community.general.passwordstore
。
概要
使 Ansible 能够从 passwordstore.org 的 pass 工具检索、创建或更新密码。它还可以检索、创建或更新以 YAML 样式存储在密码文件中作为多行的密钥。
为了避免同时访问多个密钥时出现问题,请将
auto-expand-secmem
添加到~/.gnupg/gpg-agent.conf
中。如果无法做到这一点,请考虑使用lock=readwrite
代替。
术语
参数 |
注释 |
---|---|
查询密钥。 |
关键字参数
此部分描述查询的关键字参数。这些是在以下示例中的值 key1=value1
,key2=value2
等: lookup('community.general.passwordstore', key1=value1, key2=value2, ...)
和 query('community.general.passwordstore', key1=value1, key2=value2, ...)
参数 |
注释 |
---|---|
指定要使用的后端。 默认为
选项
配置
|
|
密码存储的目录。 如果 如果 配置
|
|
生成的密码的长度。 默认值: |
|
如何同步操作。
选项
配置
|
|
当 带单位后缀的时间, 与 默认值: 配置
|
|
关于密码文件缺失时应执行操作的偏好列表。 如果 如果设置为 如果设置为 如果设置为 选项
|
|
关于密码子密钥缺失时应执行操作的偏好。 如果设置为 如果设置为 选项
配置
|
|
使用字母数字字符。 选项
|
|
如果密码或子密钥已存在,则覆盖它。 选项
|
|
在密码文件中包含旧的(已编辑的)密码。 选项
|
|
返回密码的所有内容,而不仅仅是第一行。 选项
|
|
将密码生成信息添加到文件的末尾。 选项
|
|
指定要保存的密码,而不是生成的密码。 |
注释
注意
当关键字参数和位置参数一起使用时,必须先列出位置参数,然后再列出关键字参数:
lookup('community.general.passwordstore', term1, term2, key1=value1, key2=value2)
和query('community.general.passwordstore', term1, term2, key1=value1, key2=value2)
自 community.general 6.0.0 起,此查找支持将所有选项作为查找参数传递。
示例
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)}}"
返回值
键 |
描述 |
---|---|
密码 返回:成功 |