community.crypto.x509_certificate_pipe module – Generate and/or check OpenSSL certificates
Note
This module is part of the community.crypto collection (version 3.2.1).
You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.
To install it, use: ansible-galaxy collection install community.crypto. You need further requirements to be able to use this module, see Requirements for details.
To use it in a playbook, specify: community.crypto.x509_certificate_pipe.
New in community.crypto 1.3.0
Synopsis
- It implements a notion of provider (one of
selfsignedandownca) for your certificate. - It uses the cryptography python library to interact with OpenSSL.
- The
owncaprovider is intended for generating an OpenSSL certificate signed with your own CA (Certificate Authority) certificate (self-signed certificate). - This module allows one to (re)generate OpenSSL certificates.
Requirements
The below requirements are needed on the host that executes this module.
- cryptography >= 3.3 (if using
selfsignedorowncaprovider)
Parameters
Parameter | Comments |
|---|---|
content string | The existing certificate. |
csr_content string | Content of the Certificate Signing Request (CSR) used to generate this certificate. This is mutually exclusive with |
csr_path path | Path to the Certificate Signing Request (CSR) used to generate this certificate. This is mutually exclusive with |
force boolean | Generate the certificate, even if it already exists. Choices:
|
ignore_timestamps boolean added in community.crypto 2.0.0 | Whether the “not before” and “not after” timestamps should be ignored for idempotency checks. It is better to keep the default value Choices:
|
ownca_content string | Content of the CA (Certificate Authority) certificate. This is only used by the This is mutually exclusive with |
ownca_create_authority_key_identifier boolean | Create a Authority Key Identifier from the CA’s certificate. If the CSR provided a authority key identifier, it is ignored. The Authority Key Identifier is generated from the CA certificate’s Subject Key Identifier, if available. If it is not available, the CA certificate’s public key will be used. This is only used by the Choices:
|
ownca_create_subject_key_identifier string | Whether to create the Subject Key Identifier (SKI) from the public key. A value of A value of A value of This is only used by the Choices:
|
ownca_digest string | The digest algorithm to be used for the This is only used by the Default: |
ownca_not_after string | The point in time at which the certificate stops being valid. Time can be specified either as relative time or as absolute timestamp. Time will always be interpreted as UTC. Valid format is If this value is not specified, the certificate will stop being valid 10 years from now. Note that this value is not used to determine whether an existing certificate should be regenerated. This can be changed by setting the This is only used by the On macOS 10.15 and onwards, TLS server certificates must have a validity period of 825 days or fewer. Please see https://support.apple.com/en-us/HT210176 for more details. Default: |
ownca_not_before string | The point in time the certificate is valid from. Time can be specified either as relative time or as absolute timestamp. Time will always be interpreted as UTC. Valid format is If this value is not specified, the certificate will start being valid from now. Note that this value is not used to determine whether an existing certificate should be regenerated. This can be changed by setting the This is only used by the Default: |
ownca_path path | Remote absolute path of the CA (Certificate Authority) certificate. This is only used by the This is mutually exclusive with |
ownca_privatekey_content string | Content of the CA (Certificate Authority) private key to use when signing the certificate. This is only used by the This is mutually exclusive with |
ownca_privatekey_passphrase string | The passphrase for the This is only used by the |
ownca_privatekey_path path | Path to the CA (Certificate Authority) private key to use when signing the certificate. This is only used by the This is mutually exclusive with |
ownca_version integer | The version of the Nowadays it should almost always be This is only used by the Choices:
|
privatekey_content string | Content of the private key to use when signing the certificate. This is mutually exclusive with |
privatekey_passphrase string | The passphrase for the This is required if the private key is password protected. |
privatekey_path path | Path to the private key to use when signing the certificate. This is mutually exclusive with |
provider string / required | Name of the provider to use to generate/retrieve the OpenSSL certificate. The Choices:
|
select_crypto_backend string | Determines which crypto backend to use. The default choice is If set to Note that with community.crypto 3.0.0, all values behave the same. This option will be deprecated in a later version. We recommend to not set it explicitly. Choices:
|
selfsigned_create_subject_key_identifier string | Whether to create the Subject Key Identifier (SKI) from the public key. A value of A value of A value of This is only used by the Choices:
|
selfsigned_digest string | Digest algorithm to be used when self-signing the certificate. This is only used by the Default: |
selfsigned_not_after aliases: selfsigned_notAfter string | The point in time at which the certificate stops being valid. Time can be specified either as relative time or as absolute timestamp. Time will always be interpreted as UTC. Valid format is If this value is not specified, the certificate will stop being valid 10 years from now. Note that this value is not used to determine whether an existing certificate should be regenerated. This can be changed by setting the This is only used by the On macOS 10.15 and onwards, TLS server certificates must have a validity period of 825 days or fewer. Please see https://support.apple.com/en-us/HT210176 for more details. Default: |
selfsigned_not_before aliases: selfsigned_notBefore string | The point in time the certificate is valid from. Time can be specified either as relative time or as absolute timestamp. Time will always be interpreted as UTC. Valid format is If this value is not specified, the certificate will start being valid from now. Note that this value is not used to determine whether an existing certificate should be regenerated. This can be changed by setting the This is only used by the Default: |
selfsigned_version integer | Version of the Nowadays it should almost always be This is only used by the Choices:
|
Attributes
Attribute | Support | Description |
|---|---|---|
check_mode | Support: full Since community.crypto 3.0.0 the module ignores check mode and always behaves as if check mode is not active. | Can run in |
diff_mode | Support: full | Will return details on what has changed (or possibly needs changing in |
idempotent | Support: partial If relative timestamps are used and The option | When run twice in a row outside check mode, with the same arguments, the second invocation indicates no change. This assumes that the system controlled/queried by the module has not changed in a relevant way. |
Notes
Note
- All ASN.1 TIME values should be specified following the YYYYMMDDHHMMSSZ pattern.
- Date specified should be UTC. Minutes and seconds are mandatory.
- For security reason, when you use
owncaprovider, you should NOT run community.crypto.x509_certificate on a target machine, but on a dedicated CA machine. It is recommended not to store the CA private key on the target machine. Once signed, the certificate can be moved to the target machine. - For the
selfsignedprovider,csr_pathandcsr_contentare optional. If not provided, a certificate without any information (Subject, Subject Alternative Names, Key Usage, etc.) is created.
See Also
See also
- community.crypto.x509_certificate
-
Generate and/or check OpenSSL certificates.
- community.crypto.openssl_csr
-
Generate OpenSSL Certificate Signing Request (CSR).
- community.crypto.openssl_csr_pipe
-
Generate OpenSSL Certificate Signing Request (CSR).
- community.crypto.openssl_dhparam
-
Generate OpenSSL Diffie-Hellman Parameters.
- community.crypto.openssl_pkcs12
-
Generate OpenSSL PKCS#12 archive.
- community.crypto.openssl_privatekey
-
Generate OpenSSL private keys.
- community.crypto.openssl_privatekey_pipe
-
Generate OpenSSL private keys without disk access.
- community.crypto.openssl_publickey
-
Generate an OpenSSL public key from its private key.
Examples
---
- name: Generate a Self Signed OpenSSL certificate
community.crypto.x509_certificate_pipe:
provider: selfsigned
privatekey_path: /etc/ssl/private/ansible.com.pem
csr_path: /etc/ssl/csr/ansible.com.csr
register: result
- name: Print the certificate
ansible.builtin.debug:
var: result.certificate
# In the following example, both CSR and certificate file are stored on the
# machine where ansible-playbook is executed, while the OwnCA data (certificate,
# private key) are stored on the remote machine.
- name: (1/2) Generate an OpenSSL Certificate with the CSR provided inline
community.crypto.x509_certificate_pipe:
provider: ownca
content: "{{ lookup('ansible.builtin.file', '/etc/ssl/csr/www.ansible.com.crt') }}"
csr_content: "{{ lookup('ansible.builtin.file', '/etc/ssl/csr/www.ansible.com.csr') }}"
ownca_cert: /path/to/ca_cert.crt
ownca_privatekey: /path/to/ca_cert.key
ownca_privatekey_passphrase: hunter2
register: result
- name: (2/2) Store certificate
ansible.builtin.copy:
dest: /etc/ssl/csr/www.ansible.com.crt
content: "{{ result.certificate }}"
delegate_to: localhost
when: result is changed
# In the following example, the certificate from another machine is signed by
# our OwnCA whose private key and certificate are only available on this
# machine (where ansible-playbook is executed), without having to write
# the certificate file to disk on localhost. The CSR could have been
# provided by community.crypto.openssl_csr_pipe earlier, or also have been
# read from the remote machine.
- name: (1/3) Read certificate's contents from remote machine
ansible.builtin.slurp:
src: /etc/ssl/csr/www.ansible.com.crt
register: certificate_content
- name: (2/3) Generate an OpenSSL Certificate with the CSR provided inline
community.crypto.x509_certificate_pipe:
provider: ownca
content: "{{ certificate_content.content | b64decode }}"
csr_content: "{{ the_csr }}"
ownca_cert: /path/to/ca_cert.crt
ownca_privatekey: /path/to/ca_cert.key
ownca_privatekey_passphrase: hunter2
delegate_to: localhost
register: result
- name: (3/3) Store certificate
ansible.builtin.copy:
dest: /etc/ssl/csr/www.ansible.com.crt
content: "{{ result.certificate }}"
when: result is changed
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key | Description |
|---|---|
certificate string | The (current or generated) certificate’s content. Returned: changed or success |
Collection links
© 2012–2018 Michael DeHaan
© 2018–2025 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/projects/ansible/latest/collections/community/crypto/x509_certificate_pipe_module.html