community.crypto.x509_certificate_info – Provide information of OpenSSL X.509 certificates
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.x509_certificate_info
.
Synopsis
This module allows one to query information on OpenSSL certificates.
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
select_crypto_backend
). Please note that the PyOpenSSL backend was deprecated in Ansible 2.9 and will be removed in community.crypto 2.0.0.Note that this module was called
openssl_certificate_info
when included directly in Ansible up to version 2.9. When moved to the collectioncommunity.crypto
, it was renamed to community.crypto.x509_certificate_info. From Ansible 2.10 on, it can still be used by the old short name (or byansible.builtin.openssl_certificate_info
), which redirects tocommunity.crypto.x509_certificate_info
. When using FQCNs or when using the collections keyword, the new name community.crypto.x509_certificate_info should be used to avoid a deprecation warning.
Requirements
The below requirements are needed on the host that executes this module.
PyOpenSSL >= 0.15 or cryptography >= 1.6
Parameters
Parameter |
Comments |
---|---|
Content of the X.509 certificate in PEM format. Either path or content must be specified, but not both. |
|
Remote absolute path where the certificate file is loaded from. Either path or content must be specified, but not both. |
|
Determines which crypto backend to use. The default choice is If set to If set to Please note that the Choices:
|
|
A dict of names mapping to time specifications. Every time specified here will be checked whether the certificate is valid at this point. See the Time can be specified either as relative time or as absolute timestamp. Time will always be interpreted as UTC. Valid format is |
Notes
Note
All timestamp values are provided in ASN.1 TIME format, in other words, following the
YYYYMMDDHHMMSSZ
pattern. They are all in UTC.Supports
check_mode
.
See Also
See also
- 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.
Examples
- name: Generate a Self Signed OpenSSL certificate
community.crypto.x509_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
# Get information on the certificate
- name: Get information on generated certificate
community.crypto.x509_certificate_info:
path: /etc/ssl/crt/ansible.com.crt
register: result
- name: Dump information
ansible.builtin.debug:
var: result
# Check whether the certificate is valid or not valid at certain times, fail
# if this is not the case. The first task (x509_certificate_info) collects
# the information, and the second task (assert) validates the result and
# makes the playbook fail in case something is not as expected.
- name: Test whether that certificate is valid tomorrow and/or in three weeks
community.crypto.x509_certificate_info:
path: /etc/ssl/crt/ansible.com.crt
valid_at:
point_1: "+1d"
point_2: "+3w"
register: result
- name: Validate that certificate is valid tomorrow, but not in three weeks
assert:
that:
- result.valid_at.point_1 # valid in one day
- not result.valid_at.point_2 # not valid in three weeks
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
---|---|
The certificate’s authority cert issuer as a list of general names. Is Returned: success and if the pyOpenSSL backend is not used Sample: “[DNS:www.ansible.com, IP:1.2.3.4]” |
|
The certificate’s authority cert serial number. Is Returned: success and if the pyOpenSSL backend is not used Sample: “12345” |
|
The certificate’s authority key identifier. The identifier is returned in hexadecimal, with Is Returned: success and if the pyOpenSSL backend is not used Sample: “00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22:33” |
|
Entries in the Returned: success Sample: “[CA:TRUE, pathlen:1]” |
|
Whether the Returned: success |
|
Whether the certificate is expired (in other words, Returned: success |
|
Entries in the Returned: success Sample: “[Biometric Info, DVCS, Time Stamping]” |
|
Whether the Returned: success |
|
Returns a dictionary for every extension OID. Returned: success Sample: “{\”1.3.6.1.5.5.7.1.24\”: { \”critical\”: false, \”value\”: \”MAMCAQU=\”}}” |
|
Whether the extension is critical. Returned: success |
|
The Base64 encoded value (in DER format) of the extension. Returned: success Sample: “MAMCAQU=” |
|
Fingerprints of the DER-encoded form of the whole certificate. For every hash algorithm available, the fingerprint is computed. Returned: success Sample: “{\u0027sha256\u0027: \u0027d4:b3:aa:6d:c8:04:ce:4e:ba:f6:29:4d:92:a3:94:b0:c2:ff:bd:bf:33:63:11:43:34:0f:51:b0:95:09:2f:63\u0027, \u0027sha512\u0027: \u0027f7:07:4a:f0:b0:f0:e6:8b:95:5f:f9:e6:61:0a:32:68:f1…” |
|
The certificate’s issuer. Note that for repeated values, only the last one will be returned. Returned: success Sample: “{\”organizationName\”: \”Ansible\”, \”commonName\”: \”ca.example.com\”}” |
|
The certificate’s issuer as an ordered list of tuples. Returned: success Sample: “[[\”organizationName\”, \”Ansible\”], [\”commonName\”: \”ca.example.com\”]]” |
|
Entries in the Returned: success Sample: “[Key Agreement, Data Encipherment]” |
|
Whether the Returned: success |
|
Returned: success Sample: “20190413202428Z” |
|
Returned: success Sample: “20190331202428Z” |
|
Returned: success |
|
Whether the Returned: success |
|
The OCSP responder URI, if included in the certificate. Will be Returned: success |
|
Certificate’s public key in PEM format. Returned: success Sample: “—–BEGIN PUBLIC KEY—–\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8A…” |
|
Public key data. Depends on the public key’s type. Returned: success |
|
The curve’s name for ECC. Returned: When |
|
The RSA key’s public exponent. Returned: When |
|
The maximum number of bits of a private key. This is basically the bit size of the subgroup used. Returned: When |
|
The This is the element spanning the subgroup of the multiplicative group of the prime field used. Returned: When |
|
The RSA key’s modulus. Returned: When |
|
The This is the prime modulus upon which arithmetic takes place. Returned: When |
|
The This is a prime that divides Returned: When |
|
Bit size of modulus (RSA) or prime number (DSA). Returned: When |
|
The Returned: When |
|
For For Returned: When |
|
Fingerprints of certificate’s public key. For every hash algorithm available, the fingerprint is computed. Returned: success Sample: “{\u0027sha256\u0027: \u0027d4:b3:aa:6d:c8:04:ce:4e:ba:f6:29:4d:92:a3:94:b0:c2:ff:bd:bf:33:63:11:43:34:0f:51:b0:95:09:2f:63\u0027, \u0027sha512\u0027: \u0027f7:07:4a:f0:b0:f0:e6:8b:95:5f:f9:e6:61:0a:32:68:f1…” |
|
The certificate’s public key’s type. One of Will start with Returned: success Sample: “RSA” |
|
The certificate’s serial number. Returned: success Sample: 1234 |
|
The signature algorithm used to sign the certificate. Returned: success Sample: “sha256WithRSAEncryption” |
|
The certificate’s subject as a dictionary. Note that for repeated values, only the last one will be returned. Returned: success Sample: “{\”commonName\”: \”www.example.com\”, \”emailAddress\”: \”test@example.com\”}” |
|
Entries in the Returned: success Sample: “[DNS:www.ansible.com, IP:1.2.3.4]” |
|
Whether the Returned: success |
|
The certificate’s subject key identifier. The identifier is returned in hexadecimal, with Is Returned: success and if the pyOpenSSL backend is not used Sample: “00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22:33” |
|
The certificate’s subject as an ordered list of tuples. Returned: success Sample: “[[\”commonName\”, \”www.example.com\”], [\”emailAddress\”: \”test@example.com\”]]” |
|
For every time stamp provided in the valid_at option, a boolean whether the certificate is valid at that point in time or not. Returned: success |
|
The certificate version. Returned: success Sample: 3 |
Authors
Felix Fontein (@felixfontein)
Yanis Guenane (@Spredzy)
Markus Teufelberger (@MarkusTeufelberger)