ansible.builtin.openssl_certificate (v2.9.27) — module

Generate and/or check OpenSSL certificates

| "added in version" 2.4 of ansible.builtin"

Authors: Yanis Guenane (@Spredzy), Markus Teufelberger (@MarkusTeufelberger)

preview | supported by community

Install Ansible via pip

Install with pip install ansible==2.9.27

Description

This module allows one to (re)generate OpenSSL certificates.

It implements a notion of provider (ie. C(selfsigned), C(ownca), C(acme), C(assertonly), C(entrust)) for your certificate.

The C(assertonly) provider is intended for use cases where one is only interested in checking properties of a supplied certificate. Please note that this provider has been deprecated in Ansible 2.9 and will be removed in Ansible 2.13. See the examples on how to emulate C(assertonly) usage with M(openssl_certificate_info), M(openssl_csr_info), M(openssl_privatekey_info) and M(assert). This also allows more flexible checks than the ones offered by the C(assertonly) provider.

The C(ownca) provider is intended for generating OpenSSL certificate signed with your own CA (Certificate Authority) certificate (self-signed 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).

Please note that the module regenerates existing certificate if it doesn't 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 I(backup) option.

It uses the pyOpenSSL or cryptography python library to interact with OpenSSL.

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 C(select_crypto_backend)). Please note that the PyOpenSSL backend was deprecated in Ansible 2.9 and will be removed in Ansible 2.13.


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Generate an OpenSSL certificate signed with your own CA certificate
  openssl_certificate:
    path: /etc/ssl/crt/ansible.com.crt
    csr_path: /etc/ssl/csr/ansible.com.csr
    ownca_path: /etc/ssl/crt/ansible_CA.crt
    ownca_privatekey_path: /etc/ssl/private/ansible_CA.pem
    provider: ownca
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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_path: /etc/ssl/private/ansible.com.pem
    acme_challenge_path: /etc/ssl/challenges/ansible.com/
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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_path: /etc/ssl/private/ansible.com.pem
    acme_challenge_path: /etc/ssl/challenges/ansible.com/
    force: yes
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Generate an Entrust certificate via the Entrust Certificate Services (ECS) API
  openssl_certificate:
    path: /etc/ssl/crt/ansible.com.crt
    csr_path: /etc/ssl/csr/ansible.com.csr
    provider: entrust
    entrust_requester_name: Jo Doe
    entrust_requester_email: jdoe@ansible.com
    entrust_requester_phone: 555-555-5555
    entrust_cert_type: STANDARD_SSL
    entrust_api_user: apiusername
    entrust_api_key: a^lv*32!cd9LnT
    entrust_api_client_cert_path: /etc/ssl/entrust/ecs-client.crt
    entrust_api_client_cert_key_path: /etc/ssl/entrust/ecs-key.crt
    entrust_api_specification_path: /etc/ssl/entrust/api-docs/cms-api-2.1.0.yaml
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# The following example shows one assertonly usage using all existing options for
# assertonly, and shows how to emulate the behavior with the openssl_certificate_info,
# openssl_csr_info, openssl_privatekey_info and assert modules:

- openssl_certificate:
    provider: assertonly
    path: /etc/ssl/crt/ansible.com.crt
    csr_path: /etc/ssl/csr/ansible.com.csr
    privatekey_path: /etc/ssl/csr/ansible.com.key
    signature_algorithms:
      - sha256WithRSAEncryption
      - sha512WithRSAEncryption
    subject:
      commonName: ansible.com
    subject_strict: yes
    issuer:
      commonName: ansible.com
    issuer_strict: yes
    has_expired: no
    version: 3
    key_usage:
      - Data Encipherment
    key_usage_strict: yes
    extended_key_usage:
      - DVCS
    extended_key_usage_strict: yes
    subject_alt_name:
      - dns:ansible.com
    subject_alt_name_strict: yes
    not_before: 20190331202428Z
    not_after: 20190413202428Z
    valid_at: "+1d10h"
    invalid_at: 20200331202428Z
    valid_in: 10  # in ten seconds
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- openssl_certificate_info:
    path: /etc/ssl/crt/ansible.com.crt
    # for valid_at, invalid_at and valid_in
    valid_at:
      one_day_ten_hours: "+1d10h"
      fixed_timestamp: 20200331202428Z
      ten_seconds: "+10"
  register: result
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- openssl_csr_info:
    # Verifies that the CSR signature is valid; module will fail if not
    path: /etc/ssl/csr/ansible.com.csr
  register: result_csr
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- openssl_privatekey_info:
    path: /etc/ssl/csr/ansible.com.key
  register: result_privatekey
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- assert:
    that:
      # When private key is specified for assertonly, this will be checked:
      - result.public_key == result_privatekey.public_key
      # When CSR is specified for assertonly, this will be checked:
      - result.public_key == result_csr.public_key
      - result.subject_ordered == result_csr.subject_ordered
      - result.extensions_by_oid == result_csr.extensions_by_oid
      # signature_algorithms check
      - "result.signature_algorithm == 'sha256WithRSAEncryption' or result.signature_algorithm == 'sha512WithRSAEncryption'"
      # subject and subject_strict
      - "result.subject.commonName == 'ansible.com'"
      - "result.subject | length == 1"  # the number must be the number of entries you check for
      # issuer and issuer_strict
      - "result.issuer.commonName == 'ansible.com'"
      - "result.issuer | length == 1"  # the number must be the number of entries you check for
      # has_expired
      - not result.expired
      # version
      - result.version == 3
      # key_usage and key_usage_strict
      - "'Data Encipherment' in result.key_usage"
      - "result.key_usage | length == 1"  # the number must be the number of entries you check for
      # extended_key_usage and extended_key_usage_strict
      - "'DVCS' in result.extended_key_usage"
      - "result.extended_key_usage | length == 1"  # the number must be the number of entries you check for
      # subject_alt_name and subject_alt_name_strict
      - "'dns:ansible.com' in result.subject_alt_name"
      - "result.subject_alt_name | length == 1"  # the number must be the number of entries you check for
      # not_before and not_after
      - "result.not_before == '20190331202428Z'"
      - "result.not_after == '20190413202428Z'"
      # valid_at, invalid_at and valid_in
      - "result.valid_at.one_day_ten_hours"  # for valid_at
      - "not result.valid_at.fixed_timestamp"  # for invalid_at
      - "result.valid_at.ten_seconds"  # for valid_in
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Examples for some checks one could use the assertonly provider for:
# (Please note that assertonly has been deprecated!)

# How to use the assertonly provider to implement and trigger your own custom certificate generation workflow:
- name: Check if a certificate is currently still valid, ignoring failures
  openssl_certificate:
    path: /etc/ssl/crt/example.com.crt
    provider: assertonly
    has_expired: no
  ignore_errors: yes
  register: validity_check
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Run custom task(s) to get a new, valid certificate in case the initial check failed
  command: superspecialSSL recreate /etc/ssl/crt/example.com.crt
  when: validity_check.failed
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Check the new certificate again for validity with the same parameters, this time failing the play if it is still invalid
  openssl_certificate:
    path: /etc/ssl/crt/example.com.crt
    provider: assertonly
    has_expired: no
  when: validity_check.failed
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Some other checks that assertonly could be used 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: no
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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

Inputs

    
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:
    - Remote absolute path where the generated certificate file should be created or is
      already located.
    required: true
    type: path

force:
    default: false
    description:
    - Generate the certificate, even if it already exists.
    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 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 certificate
      back if you overwrote it with a new one by accident.
    - This is not used by the C(assertonly) provider.
    - This option is deprecated since Ansible 2.9 and will be removed with the C(assertonly)
      provider in Ansible 2.13. For alternatives, see the example on replacing C(assertonly).
    type: bool
    version_added: '2.8'
    version_added_collection: ansible.builtin

issuer:
    description:
    - The key/value pairs that must be present in the issuer name field of the certificate.
    - If you need to specify more than one value with the same key, use a list as value.
    - This is only used by the C(assertonly) provider.
    - This option is deprecated since Ansible 2.9 and will be removed with the C(assertonly)
      provider in Ansible 2.13. For alternatives, see the example on replacing C(assertonly).
    type: dict

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:
    - The key/value pairs that must be present in the subject name field of the certificate.
    - If you need to specify more than one value with the same key, use a list as value.
    - This is only used by the C(assertonly) provider.
    - This option is deprecated since Ansible 2.9 and will be removed with the C(assertonly)
      provider in Ansible 2.13. For alternatives, see the example on replacing C(assertonly).
    type: dict

version:
    description:
    - The version of the certificate.
    - Nowadays it should almost always be 3.
    - This is only used by the C(assertonly) provider.
    - This option is deprecated since Ansible 2.9 and will be removed with the C(assertonly)
      provider in Ansible 2.13. For alternatives, see the example on replacing C(assertonly).
    type: int

csr_path:
    description:
    - Path to the Certificate Signing Request (CSR) used to generate this certificate.
    - This is not required in C(assertonly) mode.
    type: path

provider:
    choices:
    - acme
    - assertonly
    - entrust
    - ownca
    - selfsigned
    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.
    - The C(assertonly) provider has been deprecated in Ansible 2.9 and will be removed
      in Ansible 2.13. Please see the examples on how to emulate it with M(openssl_certificate_info),
      M(openssl_csr_info), M(openssl_privatekey_info) and M(assert).
    - The C(entrust) provider was added for Ansible 2.9 and requires credentials for the
      L(https://www.entrustdatacard.com/products/categories/ssl-certificates,Entrust Certificate
      Services) (ECS) API.
    - Required if I(state) is C(present).
    type: str

valid_at:
    description:
    - The certificate must be valid at this point in time.
    - The timestamp is formatted as an ASN.1 TIME.
    - This is only used by the C(assertonly) provider.
    - This option is deprecated since Ansible 2.9 and will be removed with the C(assertonly)
      provider in Ansible 2.13. For alternatives, see the example on replacing C(assertonly).
    type: str

valid_in:
    description:
    - The certificate must still be valid at this relative time offset from now.
    - Valid format is C([+-]timespec | number_of_seconds) where timespec can be an integer
      + C([w | d | h | m | s]) (e.g. C(+32w1d2h).
    - Note that if using this parameter, this module is NOT idempotent.
    - This is only used by the C(assertonly) provider.
    - This option is deprecated since Ansible 2.9 and will be removed with the C(assertonly)
      provider in Ansible 2.13. For alternatives, see the example on replacing C(assertonly).
    type: str

key_usage:
    aliases:
    - keyUsage
    description:
    - The I(key_usage) extension field must contain all these values.
    - This is only used by the C(assertonly) provider.
    - This option is deprecated since Ansible 2.9 and will be removed with the C(assertonly)
      provider in Ansible 2.13. For alternatives, see the example on replacing C(assertonly).
    elements: str
    type: list

not_after:
    aliases:
    - notAfter
    description:
    - The certificate must expire at this point in time.
    - The timestamp is formatted as an ASN.1 TIME.
    - This is only used by the C(assertonly) provider.
    - This option is deprecated since Ansible 2.9 and will be removed with the C(assertonly)
      provider in Ansible 2.13. For alternatives, see the example on replacing C(assertonly).
    type: str

acme_chain:
    default: false
    description:
    - Include the intermediate certificate to the generated certificate
    - This is only used by the C(acme) provider.
    - Note that this is only available for older versions of C(acme-tiny). New versions
      include the chain automatically, and setting I(acme_chain) to C(yes) results in
      an error.
    type: bool
    version_added: '2.5'
    version_added_collection: ansible.builtin

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

invalid_at:
    description:
    - The certificate must be invalid at this point in time.
    - The timestamp is formatted as an ASN.1 TIME.
    - This is only used by the C(assertonly) provider.
    - This option is deprecated since Ansible 2.9 and will be removed with the C(assertonly)
      provider in Ansible 2.13. For alternatives, see the example on replacing C(assertonly).
    type: str

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.
    - This is only used by the C(assertonly) provider.
    - This option is deprecated since Ansible 2.9 and will be removed with the C(assertonly)
      provider in Ansible 2.13. For alternatives, see the example on replacing C(assertonly).
    type: str

ownca_path:
    description:
    - Remote absolute path of the CA (Certificate Authority) certificate.
    - This is only used by the C(ownca) provider.
    type: path
    version_added: '2.7'
    version_added_collection: ansible.builtin

has_expired:
    default: false
    description:
    - Checks if the certificate is expired/not expired at the time the module is executed.
    - This is only used by the C(assertonly) provider.
    - This option is deprecated since Ansible 2.9 and will be removed with the C(assertonly)
      provider in Ansible 2.13. For alternatives, see the example on replacing C(assertonly).
    type: bool

ownca_digest:
    default: sha256
    description:
    - The digest algorithm to be used for the C(ownca) certificate.
    - This is only used by the C(ownca) provider.
    type: str
    version_added: '2.7'
    version_added_collection: ansible.builtin

issuer_strict:
    default: false
    description:
    - If set to C(yes), the I(issuer) field must contain only these values.
    - This is only used by the C(assertonly) provider.
    - This option is deprecated since Ansible 2.9 and will be removed with the C(assertonly)
      provider in Ansible 2.13. For alternatives, see the example on replacing C(assertonly).
    type: bool
    version_added: '2.5'
    version_added_collection: ansible.builtin

ownca_version:
    default: 3
    description:
    - The version of the C(ownca) certificate.
    - Nowadays it should almost always be C(3).
    - This is only used by the C(ownca) provider.
    type: int
    version_added: '2.7'
    version_added_collection: ansible.builtin

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

subject_strict:
    default: false
    description:
    - If set to C(yes), the I(subject) field must contain only these values.
    - This is only used by the C(assertonly) provider.
    - This option is deprecated since Ansible 2.9 and will be removed with the C(assertonly)
      provider in Ansible 2.13. For alternatives, see the example on replacing C(assertonly).
    type: bool
    version_added: '2.5'
    version_added_collection: ansible.builtin

entrust_api_key:
    description:
    - The key (password) for authentication to the Entrust Certificate Services (ECS)
      API.
    - This is only used by the C(entrust) provider.
    - This is required if the provider is C(entrust).
    type: str
    version_added: '2.9'
    version_added_collection: ansible.builtin

ownca_not_after:
    default: +3650d
    description:
    - 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 C([+-]timespec | ASN.1 TIME) where timespec can be an integer +
      C([w | d | h | m | s]) (e.g. C(+32w1d2h).
    - Note that if using relative time this module is NOT idempotent.
    - If this value is not specified, the certificate will stop being valid 10 years from
      now.
    - This is only used by the C(ownca) provider.
    type: str
    version_added: '2.7'
    version_added_collection: ansible.builtin

privatekey_path:
    description:
    - Path to the private key to use when signing the certificate.
    type: path

entrust_api_user:
    description:
    - The username for authentication to the Entrust Certificate Services (ECS) API.
    - This is only used by the C(entrust) provider.
    - This is required if the provider is C(entrust).
    type: str
    version_added: '2.9'
    version_added_collection: ansible.builtin

key_usage_strict:
    aliases:
    - keyUsage_strict
    default: false
    description:
    - If set to C(yes), the I(key_usage) extension field must contain only these values.
    - This is only used by the C(assertonly) provider.
    - This option is deprecated since Ansible 2.9 and will be removed with the C(assertonly)
      provider in Ansible 2.13. For alternatives, see the example on replacing C(assertonly).
    type: bool

ownca_not_before:
    default: +0s
    description:
    - 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 C([+-]timespec | ASN.1 TIME) where timespec can be an integer +
      C([w | d | h | m | s]) (e.g. C(+32w1d2h).
    - Note that if using relative time this module is NOT idempotent.
    - If this value is not specified, the certificate will start being valid from now.
    - This is only used by the C(ownca) provider.
    type: str
    version_added: '2.7'
    version_added_collection: ansible.builtin

subject_alt_name:
    aliases:
    - subjectAltName
    description:
    - The I(subject_alt_name) extension field must contain these values.
    - This is only used by the C(assertonly) provider.
    - This option is deprecated since Ansible 2.9 and will be removed with the C(assertonly)
      provider in Ansible 2.13. For alternatives, see the example on replacing C(assertonly).
    elements: str
    type: list

entrust_cert_type:
    choices:
    - STANDARD_SSL
    - ADVANTAGE_SSL
    - UC_SSL
    - EV_SSL
    - WILDCARD_SSL
    - PRIVATE_SSL
    - PD_SSL
    - CDS_ENT_LITE
    - CDS_ENT_PRO
    - SMIME_ENT
    default: STANDARD_SSL
    description:
    - Specify the type of certificate requested.
    - This is only used by the C(entrust) provider.
    type: str
    version_added: '2.9'
    version_added_collection: ansible.builtin

entrust_not_after:
    default: +365d
    description:
    - 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 C(ASN.1 TIME) such as C(2019-06-18).
    - A valid relative time format is C([+-]timespec) where timespec can be an integer
      + C([w | d | h | m | s]), such as C(+365d) or C(+32w1d2h)).
    - 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 C(entrust) provider.
    type: str
    version_added: '2.9'
    version_added_collection: ansible.builtin

selfsigned_digest:
    default: sha256
    description:
    - Digest algorithm to be used when self-signing the certificate.
    - This is only used by the C(selfsigned) provider.
    type: str

extended_key_usage:
    aliases:
    - extendedKeyUsage
    description:
    - The I(extended_key_usage) extension field must contain all these values.
    - This is only used by the C(assertonly) provider.
    - This option is deprecated since Ansible 2.9 and will be removed with the C(assertonly)
      provider in Ansible 2.13. For alternatives, see the example on replacing C(assertonly).
    elements: str
    type: list

selfsigned_version:
    default: 3
    description:
    - Version of the C(selfsigned) certificate.
    - Nowadays it should almost always be C(3).
    - This is only used by the C(selfsigned) provider.
    type: int
    version_added: '2.5'
    version_added_collection: ansible.builtin

acme_challenge_path:
    description:
    - The path to the ACME challenge directory that is served on U(http://<HOST>:80/.well-known/acme-challenge/)
    - This is only used by the C(acme) provider.
    type: path

acme_accountkey_path:
    description:
    - The path to the accountkey for the C(acme) provider.
    - This is only used by the C(acme) provider.
    type: path

selfsigned_not_after:
    aliases:
    - selfsigned_notAfter
    default: +3650d
    description:
    - 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 C([+-]timespec | ASN.1 TIME) where timespec can be an integer +
      C([w | d | h | m | s]) (e.g. C(+32w1d2h).
    - Note that if using relative time this module is NOT idempotent.
    - If this value is not specified, the certificate will stop being valid 10 years from
      now.
    - This is only used by the C(selfsigned) provider.
    type: str

signature_algorithms:
    description:
    - A list of algorithms that you would accept the certificate to be signed with (e.g.
      ['sha256WithRSAEncryption', 'sha512WithRSAEncryption']).
    - This is only used by the C(assertonly) provider.
    - This option is deprecated since Ansible 2.9 and will be removed with the C(assertonly)
      provider in Ansible 2.13. For alternatives, see the example on replacing C(assertonly).
    elements: str
    type: list

ownca_privatekey_path:
    description:
    - Path to the CA (Certificate Authority) private key to use when signing the certificate.
    - This is only used by the C(ownca) provider.
    type: path
    version_added: '2.7'
    version_added_collection: ansible.builtin

privatekey_passphrase:
    description:
    - The passphrase for the I(privatekey_path).
    - This is required if the private key is password protected.
    type: str

select_crypto_backend:
    choices:
    - auto
    - cryptography
    - pyopenssl
    default: auto
    description:
    - Determines which crypto backend to use.
    - The default choice is C(auto), which tries to use C(cryptography) if available,
      and falls back to C(pyopenssl).
    - If set to C(pyopenssl), will try to use the L(pyOpenSSL,https://pypi.org/project/pyOpenSSL/)
      library.
    - If set to C(cryptography), will try to use the L(cryptography,https://cryptography.io/)
      library.
    - Please note that the C(pyopenssl) backend has been deprecated in Ansible 2.9, and
      will be removed in Ansible 2.13. From that point on, only the C(cryptography) backend
      will be available.
    type: str
    version_added: '2.8'
    version_added_collection: ansible.builtin

selfsigned_not_before:
    aliases:
    - selfsigned_notBefore
    default: +0s
    description:
    - 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 C([+-]timespec | ASN.1 TIME) where timespec can be an integer +
      C([w | d | h | m | s]) (e.g. C(+32w1d2h).
    - Note that if using relative time this module is NOT idempotent.
    - If this value is not specified, the certificate will start being valid from now.
    - This is only used by the C(selfsigned) provider.
    type: str

entrust_requester_name:
    description:
    - The name of the requester of the certificate (for tracking purposes).
    - This is only used by the C(entrust) provider.
    - This is required if the provider is C(entrust).
    type: str
    version_added: '2.9'
    version_added_collection: ansible.builtin

entrust_requester_email:
    description:
    - The email of the requester of the certificate (for tracking purposes).
    - This is only used by the C(entrust) provider.
    - This is required if the provider is C(entrust).
    type: str
    version_added: '2.9'
    version_added_collection: ansible.builtin

entrust_requester_phone:
    description:
    - The phone number of the requester of the certificate (for tracking purposes).
    - This is only used by the C(entrust) provider.
    - This is required if the provider is C(entrust).
    type: str
    version_added: '2.9'
    version_added_collection: ansible.builtin

subject_alt_name_strict:
    aliases:
    - subjectAltName_strict
    default: false
    description:
    - If set to C(yes), the I(subject_alt_name) extension field must contain only these
      values.
    - This is only used by the C(assertonly) provider.
    - This option is deprecated since Ansible 2.9 and will be removed with the C(assertonly)
      provider in Ansible 2.13. For alternatives, see the example on replacing C(assertonly).
    type: bool

extended_key_usage_strict:
    aliases:
    - extendedKeyUsage_strict
    default: false
    description:
    - If set to C(yes), the I(extended_key_usage) extension field must contain only these
      values.
    - This is only used by the C(assertonly) provider.
    - This option is deprecated since Ansible 2.9 and will be removed with the C(assertonly)
      provider in Ansible 2.13. For alternatives, see the example on replacing C(assertonly).
    type: bool

ownca_privatekey_passphrase:
    description:
    - The passphrase for the I(ownca_privatekey_path).
    - This is only used by the C(ownca) provider.
    type: str
    version_added: '2.7'
    version_added_collection: ansible.builtin

entrust_api_client_cert_path:
    description:
    - The path to the client certificate used to authenticate to the Entrust Certificate
      Services (ECS) API.
    - This is only used by the C(entrust) provider.
    - This is required if the provider is C(entrust).
    type: path
    version_added: '2.9'
    version_added_collection: ansible.builtin

entrust_api_specification_path:
    default: https://cloud.entrust.net/EntrustCloud/documentation/cms-api-2.1.0.yaml
    description:
    - 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 C(entrust) provider.
    type: path
    version_added: '2.9'
    version_added_collection: ansible.builtin

entrust_api_client_cert_key_path:
    description:
    - 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 C(entrust) provider.
    - This is required if the provider is C(entrust).
    type: path
    version_added: '2.9'
    version_added_collection: ansible.builtin

ownca_create_subject_key_identifier:
    choices:
    - create_if_not_provided
    - always_create
    - never_create
    default: create_if_not_provided
    description:
    - Whether to create the Subject Key Identifier (SKI) from the public key.
    - A value of C(create_if_not_provided) (default) only creates a SKI when the CSR does
      not provide one.
    - A value of C(always_create) always creates a SKI. If the CSR provides one, that
      one is ignored.
    - A value of C(never_create) never creates a SKI. If the CSR provides one, that one
      is used.
    - This is only used by the C(ownca) provider.
    - Note that this is only supported if the C(cryptography) backend is used!
    type: str
    version_added: '2.9'
    version_added_collection: ansible.builtin

ownca_create_authority_key_identifier:
    default: true
    description:
    - 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 C(ownca) provider.
    - Note that this is only supported if the C(cryptography) backend is used!
    type: bool
    version_added: '2.9'
    version_added_collection: ansible.builtin

selfsigned_create_subject_key_identifier:
    choices:
    - create_if_not_provided
    - always_create
    - never_create
    default: create_if_not_provided
    description:
    - Whether to create the Subject Key Identifier (SKI) from the public key.
    - A value of C(create_if_not_provided) (default) only creates a SKI when the CSR does
      not provide one.
    - A value of C(always_create) always creates a SKI. If the CSR provides one, that
      one is ignored.
    - A value of C(never_create) never creates a SKI. If the CSR provides one, that one
      is used.
    - This is only used by the C(selfsigned) provider.
    - Note that this is only supported if the C(cryptography) backend is used!
    type: str
    version_added: '2.9'
    version_added_collection: ansible.builtin

Outputs

backup_file:
  description: Name of backup file created.
  returned: changed and if I(backup) is C(yes)
  sample: /path/to/www.ansible.com.crt.2019-03-09@11:22~
  type: str
filename:
  description: Path to the generated Certificate
  returned: changed or success
  sample: /etc/ssl/crt/www.ansible.com.crt
  type: str

See also