community / community.crypto / 2.18.0 / module / openssl_csr Generate OpenSSL Certificate Signing Request (CSR) Authors: Yanis Guenane (@Spredzy), Felix Fontein (@felixfontein)community.crypto.openssl_csr (2.18.0) — module
Install with ansible-galaxy collection install community.crypto:==2.18.0
collections: - name: community.crypto version: 2.18.0
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 O(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.
- 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: jdoe@ansible.com 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
mode: description: - The permissions the resulting filesystem object should have. - For those used to I(/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, V('644') or V('1777')) so Ansible receives a string and can do its own conversion from string into number. Adding a leading zero (for example, V(0755)) works sometimes, but can fail in loops and some other circumstances. - 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, V(u+rwx) or V(u=rw,g=r,o=r)). - If O(mode) is not specified and the destination filesystem object B(does not) exist, the default C(umask) on the system will be used when setting the mode for the newly created filesystem object. - If O(mode) is not specified and the destination filesystem object B(does) exist, the mode of the existing filesystem object will be used. - Specifying O(mode) is the best way to ensure filesystem objects are created with the correct permissions. See CVE-2020-1736 for further details. type: raw path: description: - The name of the file into which the generated OpenSSL certificate signing request will be written. required: true type: path force: default: false description: - Should the certificate signing request be forced regenerated by this ansible module. type: bool group: description: - Name of the group that should own the filesystem object, as would be fed to I(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. type: str owner: description: - Name of the user that should own the filesystem object, as would be fed to I(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. type: str state: choices: - absent - present default: present description: - Whether the certificate signing request should exist or not, taking action if the state is different from what is stated. type: str backup: default: false description: - 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. type: bool digest: default: sha256 description: - The digest used when signing the certificate signing request with the private key. type: str serole: description: - The role part of the SELinux filesystem object context. - When set to V(_default), it will use the C(role) portion of the policy if available. type: str setype: description: - The type part of the SELinux filesystem object context. - When set to V(_default), it will use the C(type) portion of the policy if available. type: str seuser: description: - The user part of the SELinux filesystem object context. - By default it uses the V(system) policy, where applicable. - When set to V(_default), it will use the C(user) portion of the policy if available. type: str selevel: description: - The level part of the SELinux filesystem object context. - This is the MLS/MCS attribute, sometimes known as the C(range). - When set to V(_default), it will use the C(level) portion of the policy if available. type: str subject: description: - 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 O(subject_ordered). - Mutually exclusive with O(subject_ordered). type: dict version: choices: - 1 default: 1 description: - The version of the certificate signing request. - The only allowed value according to L(RFC 2986,https://tools.ietf.org/html/rfc2986#section-4.1) is 1. - This option no longer accepts unsupported values since community.crypto 2.0.0. type: int key_usage: aliases: - keyUsage description: - This defines the purpose (for example encipherment, signature, certificate signing) of the key contained in the certificate. elements: str type: list attributes: aliases: - attr description: - The attributes the resulting filesystem object should have. - To get supported flags look at the man page for I(chattr) on the target system. - This string should contain the attributes in the same order as the one displayed by I(lsattr). - The C(=) operator is assumed as default, otherwise C(+) or C(-) operators need to be included in the string. type: str version_added: '2.3' version_added_collection: ansible.builtin common_name: aliases: - CN - commonName description: - The commonName field of the certificate signing request subject. type: str country_name: aliases: - C - countryName description: - The countryName field of the certificate signing request subject. type: str email_address: aliases: - E - emailAddress description: - The emailAddress field of the certificate signing request subject. type: str locality_name: aliases: - L - localityName description: - The localityName field of the certificate signing request subject. type: str unsafe_writes: default: false description: - 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. type: bool version_added: '2.2' version_added_collection: ansible.builtin return_content: default: false description: - If set to V(true), will return the (current or generated) CSR's content as RV(csr). type: bool version_added: 1.0.0 version_added_collection: community.crypto privatekey_path: description: - The path to the private key to use when signing the certificate signing request. - Either O(privatekey_path) or O(privatekey_content) must be specified if O(state) is V(present), but not both. type: path subject_ordered: description: - 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 O(subject), and any other subject field option, such as O(country_name), O(state_or_province_name), O(locality_name), O(organization_name), O(organizational_unit_name), O(common_name), or O(email_address). elements: dict type: list version_added: 2.0.0 version_added_collection: community.crypto ocsp_must_staple: aliases: - ocspMustStaple default: false description: - Indicates that the certificate should contain the OCSP Must Staple extension (U(https://tools.ietf.org/html/rfc7633)). type: bool subject_alt_name: aliases: - subjectAltName description: - Subject Alternative Name (SAN) extension to attach to the certificate signing request. - Values must be prefixed by their options. (These are C(email), C(URI), C(DNS), C(RID), C(IP), C(dirName), C(otherName), and the ones specific to your CA). - Note that if no SAN is specified, but a common name, the common name will be added as a SAN except if O(use_common_name_for_san) is set to V(false). - More at U(https://tools.ietf.org/html/rfc5280#section-4.2.1.6). elements: str type: list basic_constraints: aliases: - basicConstraints description: - Indicates basic constraints, such as if the certificate is a CA. elements: str type: list organization_name: aliases: - O - organizationName description: - The organizationName field of the certificate signing request subject. type: str extended_key_usage: aliases: - extKeyUsage - extendedKeyUsage description: - Additional restrictions (for example client authentication, server authentication) on the allowed purposes for which the public key may be used. elements: str type: list key_usage_critical: aliases: - keyUsage_critical default: false description: - Should the keyUsage extension be considered as critical. type: bool privatekey_content: description: - The content of the private key to use when signing the certificate signing request. - Either O(privatekey_path) or O(privatekey_content) must be specified if O(state) is V(present), but not both. type: str version_added: 1.0.0 version_added_collection: community.crypto authority_cert_issuer: description: - 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, C(email), C(URI), C(DNS), C(RID), C(IP), C(dirName), C(otherName), and the ones specific to your CA) - 'Example: V(DNS:ca.example.org)' - If specified, O(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 C(cryptography) backend is used! - The C(AuthorityKeyIdentifier) extension will only be added if at least one of O(authority_key_identifier), O(authority_cert_issuer) and O(authority_cert_serial_number) is specified. elements: str type: list privatekey_passphrase: description: - The passphrase for the private key. - This is required if the private key is password protected. type: str select_crypto_backend: choices: - auto - cryptography default: auto description: - Determines which crypto backend to use. - The default choice is V(auto), which tries to use C(cryptography) if available. - If set to V(cryptography), will try to use the L(cryptography,https://cryptography.io/) library. type: str state_or_province_name: aliases: - ST - stateOrProvinceName description: - The stateOrProvinceName field of the certificate signing request subject. type: str subject_key_identifier: description: - The subject key identifier as a hex string, where two bytes are separated by colons. - 'Example: V(00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22:33)' - 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 O(create_subject_key_identifier) is V(false). - Note that this is only supported if the C(cryptography) backend is used! type: str crl_distribution_points: description: - Allows to specify one or multiple CRL distribution points. - Only supported by the C(cryptography) backend. elements: dict suboptions: crl_issuer: description: - Information about the issuer of the CRL. elements: str type: list full_name: description: - Describes how the CRL can be retrieved. - Mutually exclusive with O(crl_distribution_points[].relative_name). - 'Example: V(URI:https://ca.example.com/revocations.crl).' elements: str type: list reasons: choices: - key_compromise - ca_compromise - affiliation_changed - superseded - cessation_of_operation - certificate_hold - privilege_withdrawn - aa_compromise description: - List of reasons that this distribution point can be used for when performing revocation checks. elements: str type: list relative_name: description: - Describes how the CRL can be retrieved relative to the CRL issuer. - Mutually exclusive with O(crl_distribution_points[].full_name). - 'Example: V(/CN=example.com).' - Can only be used when cryptography >= 1.6 is installed. elements: str type: list type: list version_added: 1.4.0 version_added_collection: community.crypto use_common_name_for_san: aliases: - useCommonNameForSAN default: true description: - If set to V(true), the module will fill the common name in for O(subject_alt_name) with C(DNS:) prefix if no SAN is specified. type: bool authority_key_identifier: description: - The authority key identifier as a hex string, where two bytes are separated by colons. - 'Example: V(00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22:33)' - 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 C(cryptography) backend is used! - The C(AuthorityKeyIdentifier) extension will only be added if at least one of O(authority_key_identifier), O(authority_cert_issuer) and O(authority_cert_serial_number) is specified. type: str organizational_unit_name: aliases: - OU - organizationalUnitName description: - The organizationalUnitName field of the certificate signing request subject. type: str name_constraints_critical: default: false description: - Should the Name Constraints extension be considered as critical. type: bool version_added: 1.1.0 version_added_collection: community.crypto name_constraints_excluded: description: - For CA certificates, this specifies a list of identifiers which describe subtrees of names that this CA is B(not) allowed to issue certificates for. - Values must be prefixed by their options. (That is, C(email), C(URI), C(DNS), C(RID), C(IP), C(dirName), C(otherName), and the ones specific to your CA). elements: str type: list version_added: 1.1.0 version_added_collection: community.crypto ocsp_must_staple_critical: aliases: - ocspMustStaple_critical default: false description: - 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 U(https://tools.ietf.org/html/rfc7633#section-4)). type: bool subject_alt_name_critical: aliases: - subjectAltName_critical default: false description: - Should the subjectAltName extension be considered as critical. type: bool basic_constraints_critical: aliases: - basicConstraints_critical default: false description: - Should the basicConstraints extension be considered as critical. type: bool name_constraints_permitted: description: - 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, C(email), C(URI), C(DNS), C(RID), C(IP), C(dirName), C(otherName), and the ones specific to your CA). elements: str type: list version_added: 1.1.0 version_added_collection: community.crypto extended_key_usage_critical: aliases: - extKeyUsage_critical - extendedKeyUsage_critical default: false description: - Should the extkeyUsage extension be considered as critical. type: bool authority_cert_serial_number: description: - The authority cert serial number. - If specified, O(authority_cert_issuer) must also be specified. - Note that this is only supported if the C(cryptography) backend is used! - 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 C(AuthorityKeyIdentifier) extension will only be added if at least one of O(authority_key_identifier), O(authority_cert_issuer) and O(authority_cert_serial_number) is specified. - This option accepts an B(integer). If you want to provide serial numbers as colon-separated hex strings, such as C(11:22:33), you need to convert them to an integer with P(community.crypto.parse_serial#filter). type: int create_subject_key_identifier: default: false description: - 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 C(cryptography) backend is used! type: bool
backup_file: description: Name of backup file created. returned: changed and if O(backup) is V(true) sample: /path/to/www.ansible.com.csr.2019-03-09@11:22~ type: str basicConstraints: description: Indicates if the certificate belongs to a CA elements: str returned: changed or success sample: - CA:TRUE - pathLenConstraint:0 type: list csr: description: The (current or generated) CSR's content. returned: if O(state) is V(present) and O(return_content) is V(true) type: str version_added: 1.0.0 version_added_collection: community.crypto extendedKeyUsage: description: Additional restriction on the public key purposes elements: str returned: changed or success sample: - clientAuth type: list filename: description: Path to the generated Certificate Signing Request returned: changed or success sample: /etc/ssl/csr/www.ansible.com.csr type: str keyUsage: description: Purpose for which the public key may be used elements: str returned: changed or success sample: - digitalSignature - keyAgreement type: list name_constraints_excluded: description: List of excluded subtrees the CA cannot sign certificates for. elements: str returned: changed or success sample: - email:.com type: list version_added: 1.1.0 version_added_collection: community.crypto name_constraints_permitted: description: List of permitted subtrees to sign certificates for. elements: str returned: changed or success sample: - email:.somedomain.com type: list version_added: 1.1.0 version_added_collection: community.crypto ocsp_must_staple: description: Indicates whether the certificate has the OCSP Must Staple feature enabled returned: changed or success sample: false type: bool privatekey: description: - Path to the TLS/SSL private key the CSR was generated for - Will be V(none) if the private key has been provided in O(privatekey_content). returned: changed or success sample: /etc/ssl/private/ansible.com.pem type: str subject: description: A list of the subject tuples attached to the CSR elements: list returned: changed or success sample: - - CN - www.ansible.com - - O - Ansible type: list subjectAltName: description: The alternative names this CSR is valid for elements: str returned: changed or success sample: - DNS:www.ansible.com - DNS:m.ansible.com type: list