community.crypto.x509_certificate_pipe – Generate and/or check OpenSSL certificates
Note
This plugin is part of the community.crypto collection (version 1.9.8).
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
.
To use it in a playbook, specify: community.crypto.x509_certificate_pipe
.
New in version 1.3.0: of community.crypto
Synopsis
If both the cryptography and PyOpenSSL libraries are available (and meet the minimum version requirements) cryptography will be preferred as a backend over PyOpenSSL (unless the backend is forced with
select_crypto_backend
). Please note that the PyOpenSSL backend was deprecated in Ansible 2.9 and will be removed in community.crypto 2.0.0.It implements a notion of provider (ie.
selfsigned
,ownca
,entrust
) for your certificate.It uses the pyOpenSSL or cryptography python library to interact with OpenSSL.
Please note that the module regenerates an existing certificate if it does not match the module’s options, or if it seems to be corrupt. If you are concerned that this could overwrite your existing certificate, consider using the backup option.
The
ownca
provider 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.
PyOpenSSL >= 0.15 or cryptography >= 1.6 (if using
selfsigned
,ownca
orassertonly
provider)
Parameters
Parameter |
Comments |
---|---|
The existing certificate. |
|
Content of the Certificate Signing Request (CSR) used to generate this certificate. This is mutually exclusive with csr_path. |
|
Path to the Certificate Signing Request (CSR) used to generate this certificate. This is mutually exclusive with csr_content. |
|
The path to the private key of the client certificate used to authenticate to the Entrust Certificate Services (ECS) API. This is only used by the This is required if the provider is |
|
The path to the client certificate used to authenticate to the Entrust Certificate Services (ECS) API. This is only used by the This is required if the provider is |
|
The key (password) for authentication to the Entrust Certificate Services (ECS) API. This is only used by the This is required if the provider is |
|
The path to the specification file defining the Entrust Certificate Services (ECS) API configuration. You can use this to keep a local copy of the specification to avoid downloading it every time the module is used. This is only used by the Default: “https://cloud.entrust.net/EntrustCloud/documentation/cms-api-2.1.0.yaml” |
|
The username for authentication to the Entrust Certificate Services (ECS) API. This is only used by the This is required if the provider is |
|
Specify the type of certificate requested. This is only used by the Choices:
|
|
The point in time at which the certificate stops being valid. Time can be specified either as relative time or as an absolute timestamp. A valid absolute time format is A valid relative time format is Time will always be interpreted as UTC. Note that only the date (day, month, year) is supported for specifying the expiry date of the issued certificate. The full date-time is adjusted to EST (GMT -5:00) before issuance, which may result in a certificate with an expiration date one day earlier than expected if a relative time is used. The minimum certificate lifetime is 90 days, and maximum is three years. If this value is not specified, the certificate will stop being valid 365 days the date of issue. This is only used by the Default: “+365d” |
|
The email of the requester of the certificate (for tracking purposes). This is only used by the This is required if the provider is |
|
The name of the requester of the certificate (for tracking purposes). This is only used by the This is required if the provider is |
|
The phone number of the requester of the certificate (for tracking purposes). This is only used by the This is required if the provider is |
|
Generate the certificate, even if it already exists. Choices:
|
|
Content of the CA (Certificate Authority) certificate. This is only used by the This is mutually exclusive with ownca_path. |
|
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 Note that this is only supported if the Choices:
|
|
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 Note that this is only supported if the Choices:
|
|
The digest algorithm to be used for the This is only used by the Default: “sha256” |
|
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 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: “+3650d” |
|
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 is only used by the Default: “+0s” |
|
Remote absolute path of the CA (Certificate Authority) certificate. This is only used by the This is mutually exclusive with ownca_content. |
|
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_path. |
|
The passphrase for the ownca_privatekey_path resp. ownca_privatekey_content. This is only used by the |
|
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_privatekey_content. |
|
The version of the Nowadays it should almost always be This is only used by the Default: 3 |
|
Path to the private key to use when signing the certificate. This is mutually exclusive with privatekey_path. |
|
The passphrase for the privatekey_path resp. privatekey_content. This is required if the private key is password protected. |
|
Path to the private key to use when signing the certificate. This is mutually exclusive with privatekey_content. |
|
Name of the provider to use to generate/retrieve the OpenSSL certificate. The Choices:
|
|
Determines which crypto backend to use. The default choice is If set to If set to Please note that the Choices:
|
|
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 Note that this is only supported if the Choices:
|
|
Digest algorithm to be used when self-signing the certificate. This is only used by the Default: “sha256” |
|
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 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: “+3650d” |
|
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 is only used by the Default: “+0s” |
|
Version of the Nowadays it should almost always be This is only used by the Default: 3 |
Notes
Note
Supports
check_mode
.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
ownca
provider, 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
selfsigned
provider, csr_path and csr_content are 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
The official documentation on the community.crypto.x509_certificate module.
- community.crypto.openssl_csr
The official documentation on the community.crypto.openssl_csr module.
- community.crypto.openssl_csr_pipe
The official documentation on the community.crypto.openssl_csr_pipe module.
- community.crypto.openssl_dhparam
The official documentation on the community.crypto.openssl_dhparam module.
- community.crypto.openssl_pkcs12
The official documentation on the community.crypto.openssl_pkcs12 module.
- community.crypto.openssl_privatekey
The official documentation on the community.crypto.openssl_privatekey module.
- community.crypto.openssl_privatekey_pipe
The official documentation on the community.crypto.openssl_privatekey_pipe module.
- community.crypto.openssl_publickey
The official documentation on the community.crypto.openssl_publickey module.
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('file', '/etc/ssl/csr/www.ansible.com.crt') }}"
csr_content: "{{ lookup('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 |
---|---|
The (current or generated) certificate’s content. Returned: changed or success |
Authors
Yanis Guenane (@Spredzy)
Markus Teufelberger (@MarkusTeufelberger)
Felix Fontein (@felixfontein)