ansible / ansible.builtin / v2.4.6.0-1 / module / openssl_certificate Generate and/or check OpenSSL certificates | "added in version" 2.4 of ansible.builtin" Authors: Yanis Guenane (@Spredzy), Markus Teufelberger (@MarkusTeufelberger) preview | supported by communityansible.builtin.openssl_certificate (v2.4.6.0-1) — module
pip
Install with pip install ansible==2.4.6.0.post1
This module allows one to (re)generate OpenSSL certificates. It implements a notion of provider (ie. C(selfsigned), C(acme), C(assertonly)) for your certificate. The 'assertonly' provider is intended for use cases where one is only interested in checking properties of a supplied certificate. Many properties that can be specified in this module are for validation of an existing or newly generated certificate. The proper place to specify them, if you want to receive a certificate with these properties is a CSR (Certificate Signing Request). It uses the pyOpenSSL python library to interact with OpenSSL.
- name: Generate a Self Signed OpenSSL certificate openssl_certificate: path: /etc/ssl/crt/ansible.com.crt privatekey_path: /etc/ssl/private/ansible.com.pem csr_path: /etc/ssl/csr/ansible.com.csr provider: selfsigned
- name: Generate a Let's Encrypt Certificate openssl_certificate: path: /etc/ssl/crt/ansible.com.crt csr_path: /etc/ssl/csr/ansible.com.csr provider: acme acme_accountkey: /etc/ssl/private/ansible.com.pem acme_challenge_path: /etc/ssl/challenges/ansible.com/
- name: Force (re-)generate a new Let's Encrypt Certificate openssl_certificate: path: /etc/ssl/crt/ansible.com.crt csr_path: /etc/ssl/csr/ansible.com.csr provider: acme acme_accountkey: /etc/ssl/private/ansible.com.pem acme_challenge_path: /etc/ssl/challenges/ansible.com/ force: True
# Examples for some checks one could use the assertonly provider for: - name: Verify that an existing certificate was issued by the Let's Encrypt CA and is currently still valid openssl_certificate: path: /etc/ssl/crt/example.com.crt provider: assertonly issuer: O: Let's Encrypt has_expired: False
- name: Ensure that a certificate uses a modern signature algorithm (no SHA1, MD5 or DSA) openssl_certificate: path: /etc/ssl/crt/example.com.crt provider: assertonly signature_algorithms: - sha224WithRSAEncryption - sha256WithRSAEncryption - sha384WithRSAEncryption - sha512WithRSAEncryption - sha224WithECDSAEncryption - sha256WithECDSAEncryption - sha384WithECDSAEncryption - sha512WithECDSAEncryption
- name: Ensure that the existing certificate belongs to the specified private key openssl_certificate: path: /etc/ssl/crt/example.com.crt privatekey_path: /etc/ssl/private/example.com.pem provider: assertonly
- name: Ensure that the existing certificate is still valid at the winter solstice 2017 openssl_certificate: path: /etc/ssl/crt/example.com.crt provider: assertonly valid_at: 20171221162800Z
- name: Ensure that the existing certificate is still valid 2 weeks (1209600 seconds) from now openssl_certificate: path: /etc/ssl/crt/example.com.crt provider: assertonly valid_in: 1209600
- name: Ensure that the existing certificate is only used for digital signatures and encrypting other keys openssl_certificate: path: /etc/ssl/crt/example.com.crt provider: assertonly key_usage: - digitalSignature - keyEncipherment key_usage_strict: true
- name: Ensure that the existing certificate can be used for client authentication openssl_certificate: path: /etc/ssl/crt/example.com.crt provider: assertonly extended_key_usage: - clientAuth
- name: Ensure that the existing certificate can only be used for client authentication and time stamping openssl_certificate: path: /etc/ssl/crt/example.com.crt provider: assertonly extended_key_usage: - clientAuth - 1.3.6.1.5.5.7.3.8 extended_key_usage_strict: true
- name: Ensure that the existing certificate has a certain domain in its subjectAltName openssl_certificate: path: /etc/ssl/crt/example.com.crt provider: assertonly subject_alt_name: - www.example.com - test.example.com
path: description: - Remote absolute path where the generated certificate file should be created or is already located. required: true force: default: false description: - Generate the certificate, even if it already exists. type: bool state: choices: - present - absent default: present description: - Whether the certificate should exist or not, taking action if the state is different from what is stated. issuer: description: - Key/value pairs that must be present in the issuer name field of the certificate subject: description: - Key/value pairs that must be present in the subject name field of the certificate version: description: - Version of the certificate. Nowadays it should almost always be 3. csr_path: description: - Path to the Certificate Signing Request (CSR) used to generate this certificate. This is not required in C(assertonly) mode. provider: choices: - selfsigned - assertonly - acme description: - Name of the provider to use to generate/retrieve the OpenSSL certificate. The C(assertonly) provider will not generate files and fail if the certificate file is missing. required: true valid_at: description: - The certificate must be valid at this point in time. The timestamp is formatted as an ASN.1 TIME. valid_in: description: - The certificate must still be valid in I(valid_in) seconds from now. key_usage: aliases: - keyUsage description: - The I(key_usage) extension field must contain all these values. not_after: aliases: - notAfter description: - The certificate must expire at this point in time. The timestamp is formatted as an ASN.1 TIME. invalid_at: description: - The certificate must be invalid at this point in time. The timestamp is formatted as an ASN.1 TIME. not_before: aliases: - notBefore description: - The certificate must start to become valid at this point in time. The timestamp is formatted as an ASN.1 TIME. has_expired: default: false description: - Checks if the certificate is expired/not expired at the time the module is executed. type: bool acme_accountkey: description: - Path to the accountkey for the C(acme) provider privatekey_path: description: - Path to the private key to use when signing the certificate. key_usage_strict: aliases: - keyUsage_strict default: false description: - If set to True, the I(key_usage) extension field must contain only these values. type: bool subject_alt_name: aliases: - subjectAltName description: - The I(subject_alt_name) extension field must contain these values. selfsigned_digest: default: sha256 description: - Digest algorithm to be used when self-signing the certificate extended_key_usage: aliases: - extendedKeyUsage description: - The I(extended_key_usage) extension field must contain all these values. acme_challenge_path: description: - Path to the ACME challenge directory that is served on U(http://<HOST>:80/.well-known/acme-challenge/) selfsigned_not_after: aliases: - selfsigned_notAfter description: - The timestamp at which the certificate stops being valid. The timestamp is formatted as an ASN.1 TIME. If this value is not specified, certificate will stop being valid 10 years from now. signature_algorithms: description: - list of algorithms that you would accept the certificate to be signed with (e.g. ['sha256WithRSAEncryption', 'sha512WithRSAEncryption']). privatekey_passphrase: description: - The passphrase for the I(privatekey_path). selfsigned_not_before: aliases: - selfsigned_notBefore description: - The timestamp at which the certificate starts being valid. The timestamp is formatted as an ASN.1 TIME. If this value is not specified, certificate will start being valid from now. subject_alt_name_strict: aliases: - subjectAltName_strict default: false description: - If set to True, the I(subject_alt_name) extension field must contain only these values. type: bool extended_key_usage_strict: aliases: - extendedKeyUsage_strict default: false description: - If set to True, the I(extended_key_usage) extension field must contain only these values. type: bool
filename: description: Path to the generated Certificate returned: changed or success sample: /etc/ssl/crt/www.ansible.com.crt type: string