首页 > 解决方案 > 在 Ansible 2.4 中实现 openssl 标准命令(例如 pkcs12)

问题描述

我需要在 Ansible 2.4 中实现 openssl 命令 pkcs12 最新的 Ansible 版本提供了一个名为 openssl_pkcs12 的模块,但是如何在 Ansible 2.4 中实现呢?到目前为止,我已经尝试将此命令放在 openssl_certificate 的操作中,如下所示:

name: openssl create hostcertificate.key
openssl_certificate:
  action: pkcs12
  attributes: '"-nocerts" "-nodes"'
  src: <path-to-certificate>.p12
  path: <destination-path>.key
  mode: '400'
  state: present

但它会抛出“ Unsupported paramaters for (openssl_certificate) module ”错误,因为 openssl_certificate 模块不支持此操作。我怎样才能为这个版本实现这个?

此外,我需要自动化以下 openssl 命令,因此请检查我在上述 Ansible 脚本中是否犯了任何其他错误:

openssl pkcs12 -nocerts -nodes -out <destination-path>.key -in <path-to-certificate>.p12

提前致谢

标签: linuxopensslansible-2.x

解决方案


这可以通过使用“shell”模块简单地解决。我通过使用以下 ansible 任务来做到这一点:

- name: openssl create hostcertificate.key
  shell: "openssl pkcs12 -nocerts -nodes -out <destination-path>/hostcertificate.key -in <path-to-key>/hostcertificate.p12"

推荐阅读