| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
# Copyright (c) 2017 Ansible Project |
| 5 |
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 6 |
|
| 7 |
DOCUMENTATION = r""" |
| 8 |
module: acm_certificate_info |
| 9 |
short_description: Retrieve certificate information from AWS Certificate Manager service |
| 10 |
version_added: 1.0.0 |
| 11 |
description: |
| 12 |
- Retrieve information for ACM certificates. |
| 13 |
- Note that this will not return information about uploaded keys of size 4096 bits, due to a limitation of the ACM API. |
| 14 |
- Prior to release 5.0.0 this module was called C(community.aws.aws_acm_info). |
| 15 |
The usage did not change. |
| 16 |
- Requires the IAM permissions 'acm:ListCertificates', 'acm:DescribeCertificate', 'acm:GetCertificate', 'acm:ListTagsForCertificate' |
| 17 |
options: |
| 18 |
certificate_arn: |
| 19 |
description: |
| 20 |
- If provided, the results will be filtered to show only the certificate with this ARN. |
| 21 |
- If no certificate with this ARN exists, this task will fail. |
| 22 |
- If a certificate with this ARN exists in a different region, this task will fail. |
| 23 |
aliases: |
| 24 |
- arn |
| 25 |
type: str |
| 26 |
domain_name: |
| 27 |
description: |
| 28 |
- The domain name of an ACM certificate to limit the search to. |
| 29 |
aliases: |
| 30 |
- name |
| 31 |
type: str |
| 32 |
statuses: |
| 33 |
description: |
| 34 |
- Status to filter the certificate results. |
| 35 |
choices: ['PENDING_VALIDATION', 'ISSUED', 'INACTIVE', 'EXPIRED', 'VALIDATION_TIMED_OUT', 'REVOKED', 'FAILED'] |
| 36 |
type: list |
| 37 |
elements: str |
| 38 |
tags: |
| 39 |
description: |
| 40 |
- Filter results to show only certificates with tags that match all the tags specified here. |
| 41 |
type: dict |
| 42 |
author: |
| 43 |
- Will Thames (@willthames) |
| 44 |
extends_documentation_fragment: |
| 45 |
- amazon.aws.common.modules |
| 46 |
- amazon.aws.region.modules |
| 47 |
- amazon.aws.boto3 |
| 48 |
""" |
| 49 |
|
| 50 |
EXAMPLES = r""" |
| 51 |
- name: obtain all ACM certificates |
| 52 |
community.aws.acm_certificate_info: |
| 53 |
|
| 54 |
- name: obtain all information for a single ACM certificate |
| 55 |
community.aws.acm_certificate_info: |
| 56 |
domain_name: "*.example_com" |
| 57 |
|
| 58 |
- name: obtain all certificates pending validation |
| 59 |
community.aws.acm_certificate_info: |
| 60 |
statuses: |
| 61 |
- PENDING_VALIDATION |
| 62 |
|
| 63 |
- name: obtain all certificates with tag Name=foo and myTag=bar |
| 64 |
community.aws.acm_certificate_info: |
| 65 |
tags: |
| 66 |
Name: foo |
| 67 |
myTag: bar |
| 68 |
|
| 69 |
|
| 70 |
# The output is still a list of certificates, just one item long. |
| 71 |
- name: obtain information about a certificate with a particular ARN |
| 72 |
community.aws.acm_certificate_info: |
| 73 |
certificate_arn: "arn:aws:acm:ap-southeast-2:123456789012:certificate/abcdeabc-abcd-1234-4321-abcdeabcde12" |
| 74 |
""" |
| 75 |
|
| 76 |
RETURN = r""" |
| 77 |
certificates: |
| 78 |
description: A list of certificates |
| 79 |
returned: always |
| 80 |
type: complex |
| 81 |
contains: |
| 82 |
certificate: |
| 83 |
description: The ACM Certificate body |
| 84 |
returned: when certificate creation is complete |
| 85 |
sample: '-----BEGIN CERTIFICATE-----\\nMII.....-----END CERTIFICATE-----\\n' |
| 86 |
type: str |
| 87 |
certificate_arn: |
| 88 |
description: Certificate ARN |
| 89 |
returned: always |
| 90 |
sample: arn:aws:acm:ap-southeast-2:123456789012:certificate/abcd1234-abcd-1234-abcd-123456789abc |
| 91 |
type: str |
| 92 |
certificate_chain: |
| 93 |
description: Full certificate chain for the certificate |
| 94 |
returned: when certificate creation is complete |
| 95 |
sample: '-----BEGIN CERTIFICATE-----\\nMII...\\n-----END CERTIFICATE-----\\n-----BEGIN CERTIFICATE-----\\n...' |
| 96 |
type: str |
| 97 |
created_at: |
| 98 |
description: Date certificate was created |
| 99 |
returned: always |
| 100 |
sample: '2017-08-15T10:31:19+10:00' |
| 101 |
type: str |
| 102 |
domain_name: |
| 103 |
description: Domain name for the certificate |
| 104 |
returned: always |
| 105 |
sample: '*.example.com' |
| 106 |
type: str |
| 107 |
domain_validation_options: |
| 108 |
description: Options used by ACM to validate the certificate |
| 109 |
returned: when certificate type is AMAZON_ISSUED |
| 110 |
type: complex |
| 111 |
contains: |
| 112 |
domain_name: |
| 113 |
description: Fully qualified domain name of the certificate |
| 114 |
returned: always |
| 115 |
sample: example.com |
| 116 |
type: str |
| 117 |
validation_domain: |
| 118 |
description: The domain name ACM used to send validation emails |
| 119 |
returned: always |
| 120 |
sample: example.com |
| 121 |
type: str |
| 122 |
validation_emails: |
| 123 |
description: A list of email addresses that ACM used to send domain validation emails |
| 124 |
returned: always |
| 125 |
sample: |
| 126 |
- [email protected] |
| 127 |
- [email protected] |
| 128 |
type: list |
| 129 |
elements: str |
| 130 |
validation_status: |
| 131 |
description: Validation status of the domain |
| 132 |
returned: always |
| 133 |
sample: SUCCESS |
| 134 |
type: str |
| 135 |
failure_reason: |
| 136 |
description: Reason certificate request failed |
| 137 |
returned: only when certificate issuing failed |
| 138 |
type: str |
| 139 |
sample: NO_AVAILABLE_CONTACTS |
| 140 |
in_use_by: |
| 141 |
description: A list of ARNs for the AWS resources that are using the certificate. |
| 142 |
returned: always |
| 143 |
sample: [] |
| 144 |
type: list |
| 145 |
elements: str |
| 146 |
issued_at: |
| 147 |
description: Date certificate was issued |
| 148 |
returned: always |
| 149 |
sample: '2017-01-01T00:00:00+10:00' |
| 150 |
type: str |
| 151 |
issuer: |
| 152 |
description: Issuer of the certificate |
| 153 |
returned: always |
| 154 |
sample: Amazon |
| 155 |
type: str |
| 156 |
key_algorithm: |
| 157 |
description: Algorithm used to generate the certificate |
| 158 |
returned: always |
| 159 |
sample: RSA-2048 |
| 160 |
type: str |
| 161 |
not_after: |
| 162 |
description: Date after which the certificate is not valid |
| 163 |
returned: always |
| 164 |
sample: '2019-01-01T00:00:00+10:00' |
| 165 |
type: str |
| 166 |
not_before: |
| 167 |
description: Date before which the certificate is not valid |
| 168 |
returned: always |
| 169 |
sample: '2017-01-01T00:00:00+10:00' |
| 170 |
type: str |
| 171 |
renewal_summary: |
| 172 |
description: Information about managed renewal process |
| 173 |
returned: when certificate is issued by Amazon and a renewal has been started |
| 174 |
type: complex |
| 175 |
contains: |
| 176 |
domain_validation_options: |
| 177 |
description: Options used by ACM to validate the certificate |
| 178 |
returned: when certificate type is AMAZON_ISSUED |
| 179 |
type: complex |
| 180 |
contains: |
| 181 |
domain_name: |
| 182 |
description: Fully qualified domain name of the certificate |
| 183 |
returned: always |
| 184 |
sample: example.com |
| 185 |
type: str |
| 186 |
validation_domain: |
| 187 |
description: The domain name ACM used to send validation emails |
| 188 |
returned: always |
| 189 |
sample: example.com |
| 190 |
type: str |
| 191 |
validation_emails: |
| 192 |
description: A list of email addresses that ACM used to send domain validation emails |
| 193 |
returned: always |
| 194 |
sample: |
| 195 |
- [email protected] |
| 196 |
- [email protected] |
| 197 |
type: list |
| 198 |
elements: str |
| 199 |
validation_status: |
| 200 |
description: Validation status of the domain |
| 201 |
returned: always |
| 202 |
sample: SUCCESS |
| 203 |
type: str |
| 204 |
renewal_status: |
| 205 |
description: Status of the domain renewal |
| 206 |
returned: always |
| 207 |
sample: PENDING_AUTO_RENEWAL |
| 208 |
type: str |
| 209 |
revocation_reason: |
| 210 |
description: Reason for certificate revocation |
| 211 |
returned: when the certificate has been revoked |
| 212 |
sample: SUPERCEDED |
| 213 |
type: str |
| 214 |
revoked_at: |
| 215 |
description: Date certificate was revoked |
| 216 |
returned: when the certificate has been revoked |
| 217 |
sample: '2017-09-01T10:00:00+10:00' |
| 218 |
type: str |
| 219 |
serial: |
| 220 |
description: The serial number of the certificate |
| 221 |
returned: always |
| 222 |
sample: 00:01:02:03:04:05:06:07:08:09:0a:0b:0c:0d:0e:0f |
| 223 |
type: str |
| 224 |
signature_algorithm: |
| 225 |
description: Algorithm used to sign the certificate |
| 226 |
returned: always |
| 227 |
sample: SHA256WITHRSA |
| 228 |
type: str |
| 229 |
status: |
| 230 |
description: Status of the certificate in ACM |
| 231 |
returned: always |
| 232 |
sample: ISSUED |
| 233 |
type: str |
| 234 |
subject: |
| 235 |
description: The name of the entity that is associated with the public key contained in the certificate |
| 236 |
returned: always |
| 237 |
sample: CN=*.example.com |
| 238 |
type: str |
| 239 |
subject_alternative_names: |
| 240 |
description: Subject Alternative Names for the certificate |
| 241 |
returned: always |
| 242 |
sample: |
| 243 |
- '*.example.com' |
| 244 |
type: list |
| 245 |
elements: str |
| 246 |
tags: |
| 247 |
description: Tags associated with the certificate |
| 248 |
returned: always |
| 249 |
type: dict |
| 250 |
sample: |
| 251 |
Application: helloworld |
| 252 |
Environment: test |
| 253 |
type: |
| 254 |
description: The source of the certificate |
| 255 |
returned: always |
| 256 |
sample: AMAZON_ISSUED |
| 257 |
type: str |
| 258 |
""" |
| 259 |
|
| 260 |
from ansible_collections.amazon.aws.plugins.module_utils.acm import ACMServiceManager |
| 261 |
|
| 262 |
from ansible_collections.community.aws.plugins.module_utils.modules import AnsibleCommunityAWSModule as AnsibleAWSModule |
| 263 |
|
| 264 |
|
| 265 |
def main(): |
| 266 |
argument_spec = dict( |
| 267 |
certificate_arn=dict(aliases=["arn"]), |
| 268 |
domain_name=dict(aliases=["name"]), |
| 269 |
statuses=dict( |
| 270 |
type="list", |
| 271 |
elements="str", |
| 272 |
choices=[ |
| 273 |
"PENDING_VALIDATION", |
| 274 |
"ISSUED", |
| 275 |
"INACTIVE", |
| 276 |
"EXPIRED", |
| 277 |
"VALIDATION_TIMED_OUT", |
| 278 |
"REVOKED", |
| 279 |
"FAILED", |
| 280 |
], |
| 281 |
), |
| 282 |
tags=dict(type="dict"), |
| 283 |
) |
| 284 |
module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True) |
| 285 |
acm_info = ACMServiceManager(module) |
| 286 |
|
| 287 |
client = module.client("acm") |
| 288 |
|
| 289 |
certificates = acm_info.get_certificates( |
| 290 |
client, |
| 291 |
module, |
| 292 |
domain_name=module.params["domain_name"], |
| 293 |
statuses=module.params["statuses"], |
| 294 |
arn=module.params["certificate_arn"], |
| 295 |
only_tags=module.params["tags"], |
| 296 |
) |
| 297 |
|
| 298 |
if module.params["certificate_arn"] and len(certificates) != 1: |
| 299 |
module.fail_json(msg=f"No certificate exists in this region with ARN {module.params['certificate_arn']}") |
| 300 |
|
| 301 |
module.exit_json(certificates=certificates) |
| 302 |
|
| 303 |
|
| 304 |
if __name__ == "__main__": |
| 305 |
main() |