首页 > 解决方案 > Ansible 从本地机器获取指纹哈希

问题描述

我试图从本地机器的证书存储中获取指纹,这样我就可以使用散列的变量将指纹传递给ssl_bindings任务。到目前为止,我有这个,但它返回了很多数据。我应该过滤掉数据还是有更简单的方法从现有商店获取指纹?我已经看到使用 powershell 完成了这一点,所以如果我无法解决这个问题,我可能会走这条路。

    - name: Obtain information about LocalMachines Cert Store
      community.windows.win_certificate_info:
        store_location: LocalMachine
      register: cert

标签: ansiblessl-certificate

解决方案


我最终这样做了。如果有人知道如何使用本机 ansible 模块来获取哈希,那就太酷了。

    - name: Run powershell one-liner to get the thumbprint hash
      ansible.windows.win_powershell:
        script: |
         (Get-ChildItem cert:\LocalMachine\My  | where-object { $_.Subject -like "*$hostname*" } | Select-Object -Last 1).Thumbprint
      register: hash

    - name: Add an HTTPS binding to the website using the hash
      win_iis_webbinding:
        name: "{{ iis_site }}"
        protocol: https
        port: 443
        certificate_hash: "{{ hash.output[0] }}"
        state: present

推荐阅读