ansible.windows.win_certificate_store 模块 – 管理证书存储
注意
此模块是 ansible.windows 集合 (版本 2.5.0) 的一部分。
如果您使用的是 ansible
软件包,则可能已经安装了此集合。它不包含在 ansible-core
中。要检查是否已安装它,请运行 ansible-galaxy collection list
。
要安装它,请使用:ansible-galaxy collection install ansible.windows
。
要在剧本中使用它,请指定:ansible.windows.win_certificate_store
。
概要
用于导入/导出和删除本地证书存储中的证书和密钥。
此模块不用于创建证书,仅管理作为文件或存储在存储区中的现有证书。
它可以用于导入 PEM、DER、P7B、PKCS12 (PFX) 证书并导出 PEM、DER 和 PKCS12 证书。
参数
参数 |
注释 |
---|---|
当
当设置 选项
|
|
是否允许导出私钥。 如果为 仅当 选项
|
|
指定 Windows 导入私钥时存储私钥的位置。 设置为 设置为 设置为 仅当 选项
|
|
pkcs12 证书密钥的密码。 这在读取 pkcs12 证书文件或设置密码时使用,其中 如果 pkcs12 文件未设置密码或导出文件不应设置密码,则不要设置此选项。 |
|
证书文件的路径。 当 *state* 为 当 *state* 为 |
|
如果为 如果为 如果为 导出证书时,如果 *path* 是目录,则模块将失败,否则将根据需要替换文件。 选项
|
|
导入证书或搜索证书时使用的存储位置。 当 当 当 默认值: |
|
导入证书或搜索证书时使用的存储名称。
默认值: |
|
要管理的存储类型。 使用 使用 选项
|
|
作为十六进制字符串的指纹,用于导出或删除。 请参阅示例,了解如何指定指纹。 |
注释
注意
对 PKCS12 证书和密钥执行某些操作可能会失败,并出现错误
the specified network password is not correct
,请使用 CredSSP 或 Kerberos 和凭据委派,或者使用become
来绕过这些限制。证书必须位于 Windows 主机上才能使用 *path* 设置。
在导入用于 IIS 的证书时,通常需要使用
machine
key_storage 选项,因为default
和user
都将使 IIS APPPOOL 标识无法读取私钥,并阻止将证书绑定到 https 端点。
示例
- name: Import a certificate
ansible.windows.win_certificate_store:
path: C:\Temp\cert.pem
state: present
- name: Import pfx certificate that is password protected
ansible.windows.win_certificate_store:
path: C:\Temp\cert.pfx
state: present
password: VeryStrongPasswordHere!
become: true
become_method: runas
- name: Import pfx certificate without password and set private key as un-exportable
ansible.windows.win_certificate_store:
path: C:\Temp\cert.pfx
state: present
key_exportable: false
# usually you don't set this here but it is for illustrative purposes
vars:
ansible_winrm_transport: credssp
- name: Remove a certificate based on file thumbprint
ansible.windows.win_certificate_store:
path: C:\Temp\cert.pem
state: absent
- name: Remove a certificate based on thumbprint
ansible.windows.win_certificate_store:
thumbprint: BD7AF104CF1872BDB518D95C9534EA941665FD27
state: absent
- name: Remove certificate based on thumbprint is CurrentUser/TrustedPublishers store
ansible.windows.win_certificate_store:
thumbprint: BD7AF104CF1872BDB518D95C9534EA941665FD27
state: absent
store_location: CurrentUser
store_name: TrustedPublisher
- name: Export certificate as der encoded file
ansible.windows.win_certificate_store:
path: C:\Temp\cert.cer
state: exported
file_type: der
- name: Export certificate and key as pfx encoded file
ansible.windows.win_certificate_store:
path: C:\Temp\cert.pfx
state: exported
file_type: pkcs12
password: AnotherStrongPass!
become: true
become_method: runas
become_user: SYSTEM
- name: Import certificate be used by IIS
ansible.windows.win_certificate_store:
path: C:\Temp\cert.pfx
file_type: pkcs12
password: StrongPassword!
store_location: LocalMachine
key_storage: machine
state: present
become: true
become_method: runas
become_user: SYSTEM
- name: Import certificate to be used for LDAPS
ansible.windows.win_certificate_store:
path: C:\Temp\cert.pfx
password: StrongPassword!
store_type: service
store_location: NTDS
key_exportable: false
key_storage: machine
state: present
返回值
常用的返回值已在 此处 记录,以下是此模块特有的字段
键 |
描述 |
---|---|
模块触及的证书指纹列表。 返回:成功 示例: |