community.crypto.openssl_csr_pipe – Generate OpenSSL Certificate Signing Request (CSR)
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.openssl_csr_pipe
.
New in version 1.3.0: of community.crypto
Synopsis
Please note that the module regenerates an existing CSR if it doesn’t match the module’s options, or if it seems to be corrupt.
The module can use the cryptography Python library, or the pyOpenSSL Python library. By default, it tries to detect which one is available. This can be overridden with the select_crypto_backend option. Please note that the PyOpenSSL backend was deprecated in Ansible 2.9 and will be removed in community.crypto 2.0.0.
This module allows one to (re)generate OpenSSL certificate signing requests.
This module supports the subjectAltName, keyUsage, extendedKeyUsage, basicConstraints and OCSP Must Staple extensions.
Requirements
The below requirements are needed on the host that executes this module.
Either cryptography >= 1.3
Or pyOpenSSL >= 0.15
Parameters
Parameter |
Comments |
---|---|
Names that will be present in the authority cert issuer field of the certificate signing request. Values must be prefixed by their options. (i.e., Example: If specified, authority_cert_serial_number must also be specified. Please note that commercial CAs ignore this value, respectively use a value of their own choice. Specifying this option is mostly useful for self-signed certificates or for own CAs. Note that this is only supported if the The |
|
The authority cert serial number. If specified, authority_cert_issuer must also be specified. Note that this is only supported if the Please note that commercial CAs ignore this value, respectively use a value of their own choice. Specifying this option is mostly useful for self-signed certificates or for own CAs. The |
|
The authority key identifier as a hex string, where two bytes are separated by colons. Example: Please note that commercial CAs ignore this value, respectively use a value of their own choice. Specifying this option is mostly useful for self-signed certificates or for own CAs. Note that this is only supported if the The |
|
Indicates basic constraints, such as if the certificate is a CA. |
|
Should the basicConstraints extension be considered as critical. Choices:
|
|
The commonName field of the certificate signing request subject. |
|
The existing CSR. |
|
The countryName field of the certificate signing request subject. |
|
Create the Subject Key Identifier from the public key. Please note that commercial CAs can ignore the value, respectively use a value of their own choice instead. Specifying this option is mostly useful for self-signed certificates or for own CAs. Note that this is only supported if the Choices:
|
|
Allows to specify one or multiple CRL distribution points. Only supported by the |
|
Information about the issuer of the CRL. |
|
Describes how the CRL can be retrieved. Mutually exclusive with relative_name. Example: |
|
List of reasons that this distribution point can be used for when performing revocation checks. Choices:
|
|
Describes how the CRL can be retrieved relative to the CRL issuer. Mutually exclusive with full_name. Example: Can only be used when cryptography >= 1.6 is installed. |
|
The digest used when signing the certificate signing request with the private key. Default: “sha256” |
|
The emailAddress field of the certificate signing request subject. |
|
Additional restrictions (e.g. client authentication, server authentication) on the allowed purposes for which the public key may be used. |
|
Should the extkeyUsage extension be considered as critical. Choices:
|
|
This defines the purpose (e.g. encipherment, signature, certificate signing) of the key contained in the certificate. |
|
Should the keyUsage extension be considered as critical. Choices:
|
|
The localityName field of the certificate signing request subject. |
|
Should the Name Constraints extension be considered as critical. Choices:
|
|
For CA certificates, this specifies a list of identifiers which describe subtrees of names that this CA is not allowed to issue certificates for. Values must be prefixed by their options. (i.e., |
|
For CA certificates, this specifies a list of identifiers which describe subtrees of names that this CA is allowed to issue certificates for. Values must be prefixed by their options. (i.e., |
|
Indicates that the certificate should contain the OCSP Must Staple extension (https://tools.ietf.org/html/rfc7633). Choices:
|
|
Should the OCSP Must Staple extension be considered as critical. Note that according to the RFC, this extension should not be marked as critical, as old clients not knowing about OCSP Must Staple are required to reject such certificates (see https://tools.ietf.org/html/rfc7633#section-4). Choices:
|
|
The organizationName field of the certificate signing request subject. |
|
The organizationalUnitName field of the certificate signing request subject. |
|
The content of the private key to use when signing the certificate signing request. Either privatekey_path or privatekey_content must be specified if state is |
|
The passphrase for the private key. This is required if the private key is password protected. |
|
The path to the private key to use when signing the certificate signing request. Either privatekey_path or privatekey_content must be specified if state is |
|
Determines which crypto backend to use. The default choice is If set to If set to Please note that the Choices:
|
|
The stateOrProvinceName field of the certificate signing request subject. |
|
Key/value pairs that will be present in the subject name field of the certificate signing request. If you need to specify more than one value with the same key, use a list as value. |
|
Subject Alternative Name (SAN) extension to attach to the certificate signing request. This can either be a ‘comma separated string’ or a YAML list. Values must be prefixed by their options. (i.e., Note that if no SAN is specified, but a common name, the common name will be added as a SAN except if More at https://tools.ietf.org/html/rfc5280#section-4.2.1.6. |
|
Should the subjectAltName extension be considered as critical. Choices:
|
|
The subject key identifier as a hex string, where two bytes are separated by colons. Example: Please note that commercial CAs ignore this value, respectively use a value of their own choice. Specifying this option is mostly useful for self-signed certificates or for own CAs. Note that this option can only be used if create_subject_key_identifier is Note that this is only supported if the |
|
If set to Choices:
|
|
The version of the certificate signing request. The only allowed value according to RFC 2986 is 1. This option will no longer accept unsupported values from community.crypto 2.0.0 on. Default: 1 |
Notes
Note
If the certificate signing request already exists it will be checked whether subjectAltName, keyUsage, extendedKeyUsage and basicConstraints only contain the requested values, whether OCSP Must Staple is as requested, and if the request was signed by the given private key.
See Also
See also
- community.crypto.openssl_csr
The official documentation on the community.crypto.openssl_csr module.
- community.crypto.x509_certificate
The official documentation on the community.crypto.x509_certificate module.
- community.crypto.x509_certificate_pipe
The official documentation on the community.crypto.x509_certificate_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.
- community.crypto.openssl_csr_info
The official documentation on the community.crypto.openssl_csr_info module.
Examples
- name: Generate an OpenSSL Certificate Signing Request
community.crypto.openssl_csr_pipe:
privatekey_path: /etc/ssl/private/ansible.com.pem
common_name: www.ansible.com
register: result
- debug:
var: result.csr
- name: Generate an OpenSSL Certificate Signing Request with an inline CSR
community.crypto.openssl_csr:
content: "{{ lookup('file', '/etc/ssl/csr/www.ansible.com.csr') }}"
privatekey_content: "{{ private_key_content }}"
common_name: www.ansible.com
register: result
- name: Store CSR
ansible.builtin.copy:
dest: /etc/ssl/csr/www.ansible.com.csr
content: "{{ result.csr }}"
when: result is changed
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
---|---|
Indicates if the certificate belongs to a CA Returned: changed or success Sample: [“CA:TRUE”, “pathLenConstraint:0”] |
|
The (current or generated) CSR’s content. Returned: changed or success |
|
Additional restriction on the public key purposes Returned: changed or success Sample: [“clientAuth”] |
|
Purpose for which the public key may be used Returned: changed or success Sample: [“digitalSignature”, “keyAgreement”] |
|
List of excluded subtrees the CA cannot sign certificates for. Returned: changed or success Sample: [“email:.com”] |
|
List of permitted subtrees to sign certificates for. Returned: changed or success Sample: [“email:.somedomain.com”] |
|
Indicates whether the certificate has the OCSP Must Staple feature enabled Returned: changed or success Sample: false |
|
Path to the TLS/SSL private key the CSR was generated for Will be Returned: changed or success Sample: “/etc/ssl/private/ansible.com.pem” |
|
A list of the subject tuples attached to the CSR Returned: changed or success Sample: “[(\u0027CN\u0027, \u0027www.ansible.com\u0027), (\u0027O\u0027, \u0027Ansible\u0027)]” |
|
The alternative names this CSR is valid for Returned: changed or success Sample: [“DNS:www.ansible.com”, “DNS:m.ansible.com”] |
Authors
Yanis Guenane (@Spredzy)
Felix Fontein (@felixfontein)