community.crypto.openssl_csr module – Generate OpenSSL Certificate Signing Request (CSR)
Note
This module is part of the community.crypto collection (version 2.16.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.openssl_csr
.
Synopsis
Please note that the module regenerates an existing CSR 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 CSR, consider using the
backup
option.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.
cryptography >= 1.3
Parameters
Parameter |
Comments |
---|---|
The attributes the resulting filesystem object should have. To get supported flags look at the man page for chattr on the target system. This string should contain the attributes in the same order as the one displayed by lsattr. The |
|
Names that will be present in the authority cert issuer field of the certificate signing request. Values must be prefixed by their options. (That is, Example: If 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, 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 |
|
Create a backup file including a timestamp so you can get the original CSR back if you overwrote it with a new one by accident. Choices:
|
|
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 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 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 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: |
|
The emailAddress field of the certificate signing request subject. |
|
Additional restrictions (for example 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:
|
|
Should the certificate signing request be forced regenerated by this ansible module. Choices:
|
|
Name of the group that should own the filesystem object, as would be fed to chown. When left unspecified, it uses the current group of the current user unless you are root, in which case it can preserve the previous ownership. |
|
This defines the purpose (for example 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. |
|
The permissions the resulting filesystem object should have. For those used to /usr/bin/chmod remember that modes are actually octal numbers. You must give Ansible enough information to parse them correctly. For consistent results, quote octal numbers (for example, Giving Ansible a number without following either of these rules will end up with a decimal number which will have unexpected results. As of Ansible 1.8, the mode may be specified as a symbolic mode (for example, If If Specifying |
|
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. (That is, |
|
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. (That is, |
|
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. |
|
Name of the user that should own the filesystem object, as would be fed to chown. When left unspecified, it uses the current user unless you are root, in which case it can preserve the previous ownership. Specifying a numeric username will be assumed to be a user ID and not a username. Avoid numeric usernames to avoid this confusion. |
|
The name of the file into which the generated OpenSSL certificate signing request will be written. |
|
The content of the private key to use when signing the certificate signing request. Either |
|
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 |
|
If set to Choices:
|
|
Determines which crypto backend to use. The default choice is If set to Choices:
|
|
The level part of the SELinux filesystem object context. This is the MLS/MCS attribute, sometimes known as the When set to |
|
The role part of the SELinux filesystem object context. When set to |
|
The type part of the SELinux filesystem object context. When set to |
|
The user part of the SELinux filesystem object context. By default it uses the When set to |
|
Whether the certificate signing request should exist or not, taking action if the state is different from what is stated. 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. If the order of the components is important, use Mutually exclusive with |
|
Subject Alternative Name (SAN) extension to attach to the certificate signing request. Values must be prefixed by their options. (These are 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 Note that this is only supported if the |
|
A list of dictionaries, where every dictionary must contain one key/value pair. This key/value pair will be present in the subject name field of the certificate signing request. If you want to specify more than one value with the same key in a row, you can use a list as value. Mutually exclusive with |
|
Influence when to use atomic operation to prevent data corruption or inconsistent reads from the target filesystem object. By default this module uses atomic operations to prevent data corruption or inconsistent reads from the target filesystem objects, but sometimes systems are configured or just broken in ways that prevent this. One example is docker mounted filesystem objects, which cannot be updated atomically from inside the container and can only be written in an unsafe manner. This option allows Ansible to fall back to unsafe methods of updating filesystem objects when atomic operations fail (however, it doesn’t force Ansible to perform unsafe writes). IMPORTANT! Unsafe writes are subject to race conditions and can lead to data corruption. Choices:
|
|
If set to Choices:
|
|
The version of the certificate signing request. The only allowed value according to RFC 2986 is 1. This option no longer accepts unsupported values since community.crypto 2.0.0. Choices:
|
Attributes
Attribute |
Support |
Description |
---|---|---|
Support: full |
Can run in |
|
Support: full |
Will return details on what has changed (or possibly needs changing in |
|
Support: full |
Uses Ansible’s strict file operation functions to ensure proper permissions and avoid data corruption. |
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_pipe
Generate OpenSSL Certificate Signing Request (CSR).
- community.crypto.x509_certificate
Generate and/or check OpenSSL certificates.
- community.crypto.x509_certificate_pipe
Generate and/or check OpenSSL certificates.
- 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.
- community.crypto.openssl_csr_info
Provide information of OpenSSL Certificate Signing Requests (CSR).
Examples
- name: Generate an OpenSSL Certificate Signing Request
community.crypto.openssl_csr:
path: /etc/ssl/csr/www.ansible.com.csr
privatekey_path: /etc/ssl/private/ansible.com.pem
common_name: www.ansible.com
- name: Generate an OpenSSL Certificate Signing Request with an inline key
community.crypto.openssl_csr:
path: /etc/ssl/csr/www.ansible.com.csr
privatekey_content: "{{ private_key_content }}"
common_name: www.ansible.com
- name: Generate an OpenSSL Certificate Signing Request with a passphrase protected private key
community.crypto.openssl_csr:
path: /etc/ssl/csr/www.ansible.com.csr
privatekey_path: /etc/ssl/private/ansible.com.pem
privatekey_passphrase: ansible
common_name: www.ansible.com
- name: Generate an OpenSSL Certificate Signing Request with Subject information
community.crypto.openssl_csr:
path: /etc/ssl/csr/www.ansible.com.csr
privatekey_path: /etc/ssl/private/ansible.com.pem
country_name: FR
organization_name: Ansible
email_address: [email protected]
common_name: www.ansible.com
- name: Generate an OpenSSL Certificate Signing Request with subjectAltName extension
community.crypto.openssl_csr:
path: /etc/ssl/csr/www.ansible.com.csr
privatekey_path: /etc/ssl/private/ansible.com.pem
subject_alt_name: 'DNS:www.ansible.com,DNS:m.ansible.com'
- name: Generate an OpenSSL CSR with subjectAltName extension with dynamic list
community.crypto.openssl_csr:
path: /etc/ssl/csr/www.ansible.com.csr
privatekey_path: /etc/ssl/private/ansible.com.pem
subject_alt_name: "{{ item.value | map('regex_replace', '^', 'DNS:') | list }}"
with_dict:
dns_server:
- www.ansible.com
- m.ansible.com
- name: Force regenerate an OpenSSL Certificate Signing Request
community.crypto.openssl_csr:
path: /etc/ssl/csr/www.ansible.com.csr
privatekey_path: /etc/ssl/private/ansible.com.pem
force: true
common_name: www.ansible.com
- name: Generate an OpenSSL Certificate Signing Request with special key usages
community.crypto.openssl_csr:
path: /etc/ssl/csr/www.ansible.com.csr
privatekey_path: /etc/ssl/private/ansible.com.pem
common_name: www.ansible.com
key_usage:
- digitalSignature
- keyAgreement
extended_key_usage:
- clientAuth
- name: Generate an OpenSSL Certificate Signing Request with OCSP Must Staple
community.crypto.openssl_csr:
path: /etc/ssl/csr/www.ansible.com.csr
privatekey_path: /etc/ssl/private/ansible.com.pem
common_name: www.ansible.com
ocsp_must_staple: true
- name: Generate an OpenSSL Certificate Signing Request for WinRM Certificate authentication
community.crypto.openssl_csr:
path: /etc/ssl/csr/winrm.auth.csr
privatekey_path: /etc/ssl/private/winrm.auth.pem
common_name: username
extended_key_usage:
- clientAuth
subject_alt_name: otherName:1.3.6.1.4.1.311.20.2.3;UTF8:username@localhost
- name: Generate an OpenSSL Certificate Signing Request with a CRL distribution point
community.crypto.openssl_csr:
path: /etc/ssl/csr/www.ansible.com.csr
privatekey_path: /etc/ssl/private/ansible.com.pem
common_name: www.ansible.com
crl_distribution_points:
- full_name:
- "URI:https://ca.example.com/revocations.crl"
crl_issuer:
- "URI:https://ca.example.com/"
reasons:
- key_compromise
- ca_compromise
- cessation_of_operation
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
---|---|
Name of backup file created. Returned: changed and if Sample: |
|
Indicates if the certificate belongs to a CA Returned: changed or success Sample: |
|
The (current or generated) CSR’s content. Returned: if |
|
Additional restriction on the public key purposes Returned: changed or success Sample: |
|
Path to the generated Certificate Signing Request Returned: changed or success Sample: |
|
Purpose for which the public key may be used Returned: changed or success Sample: |
|
List of excluded subtrees the CA cannot sign certificates for. Returned: changed or success Sample: |
|
List of permitted subtrees to sign certificates for. Returned: changed or success Sample: |
|
Indicates whether the certificate has the OCSP Must Staple feature enabled Returned: changed or success Sample: |
|
Path to the TLS/SSL private key the CSR was generated for Will be Returned: changed or success Sample: |
|
A list of the subject tuples attached to the CSR Returned: changed or success Sample: |
|
The alternative names this CSR is valid for Returned: changed or success Sample: |