-1

想知道如何编写 ansible-playbook 来列出 localhost 中的所有 Openssl 证书及其到期日期

4

1 回答 1

0

由于我将有一个类似的用例,并且将来可能还会有更多,因此我在 RHEL 7.9 环境中设置了一个简短的测试。

由于我在代理后面,我必须在 Bash 中为 CLI 以及 Ansible 模块指定它。

export HTTP_PROXY="http://localhost:3128"
export HTTPS_PROXY="http://localhost:3128"

来自社区收藏x509_certificate_module,因此之前需要安装。

ansible-galaxy collection install community.crypto # --ignore-certs 
Process install dependency map
Starting collection install process
Installing 'community.crypto:1.9.3' to '/home/${USER}/.ansible/collections/ansible_collections/community/crypto'

以及将集合路径添加到库中。

vi ansible.cfg
...
[defaults]
library = /usr/share/ansible/plugins/modules:~/.ansible/plugins/modules:~/.ansible/collections/ansible_collections/
...

在远程主机上需要安装Python加密模块。

- name: Make sure dependencies are resolved
  pip:
    name: cryptography
    extra_args: '--index-url https://"{{ ansible_user }}":"{{ API_KEY }}"@repository.example.com/artifactory/api/pypi/pypi-remote/simple --upgrade'
  tags: check_certs

...即使对于 Python 包,我也使用内部私有存储库服务,所以我不需要为 指定代理pip_module,但index-url这里而不是 in/etc/pip.conf

  environment:
    HTTP_PROXY: "localhost:3128"
    HTTPS_PROXY: "localhost:3128"

比收集和列出证书信息更简单。

- name: Get certificate information
  community.crypto.x509_certificate_info:
    path: /etc/pki/ca-trust/source/anchors/DC_com_DC_example_CA_cert.pem
  register: cert_info
  tags: check_certs

- name: Show certificate information
  debug:
    msg: "{{ cert_info.not_after }}"
  tags: check_certs

...由于一些互操作性问题,我发现将 POSIX 可移植文件名字符集仅用于证书文件名似乎是最好的

进一步阅读,实现部分和增强我将留给你。

文档:

于 2021-09-14T16:31:51.083 回答