community / community.aws / 1.1.0 / module / aws_acm Upload and delete certificates in the AWS Certificate Manager service | "added in version" 1.0.0 of community.aws" Authors: Matthew Davis (@matt-telstra) on behalf of Telstra Corporation Limitedcommunity.aws.aws_acm (1.1.0) — module
Install with ansible-galaxy collection install community.aws:==1.1.0
collections: - name: community.aws version: 1.1.0
Import and delete certificates in Amazon Web Service's Certificate Manager (AWS ACM).
This module does not currently interact with AWS-provided certificates. It currently only manages certificates provided to AWS by the user.
The ACM API allows users to upload multiple certificates for the same domain name, and even multiple identical certificates. This module attempts to restrict such freedoms, to be idempotent, as per the Ansible philosophy. It does this through applying AWS resource "Name" tags to ACM certificates.
When I(state=present), if there is one certificate in ACM with a C(Name) tag equal to the C(name_tag) parameter, and an identical body and chain, this task will succeed without effect.
When I(state=present), if there is one certificate in ACM a I(Name) tag equal to the I(name_tag) parameter, and a different body, this task will overwrite that certificate.
When I(state=present), if there are multiple certificates in ACM with a I(Name) tag equal to the I(name_tag) parameter, this task will fail.
When I(state=absent) and I(certificate_arn) is defined, this module will delete the ACM resource with that ARN if it exists in this region, and succeed without effect if it doesn't exist.
When I(state=absent) and I(domain_name) is defined, this module will delete all ACM resources in this AWS region with a corresponding domain name. If there are none, it will succeed without effect.
When I(state=absent) and I(certificate_arn) is not defined, and I(domain_name) is not defined, this module will delete all ACM resources in this AWS region with a corresponding I(Name) tag. If there are none, it will succeed without effect.
Note that this may not work properly with keys of size 4096 bits, due to a limitation of the ACM API.
- name: upload a self-signed certificate community.aws.aws_acm: certificate: "{{ lookup('file', 'cert.pem' ) }}" privateKey: "{{ lookup('file', 'key.pem' ) }}" name_tag: my_cert # to be applied through an AWS tag as "Name":"my_cert" region: ap-southeast-2 # AWS region
- name: create/update a certificate with a chain community.aws.aws_acm: certificate: "{{ lookup('file', 'cert.pem' ) }}" privateKey: "{{ lookup('file', 'key.pem' ) }}" name_tag: my_cert certificate_chain: "{{ lookup('file', 'chain.pem' ) }}" state: present region: ap-southeast-2 register: cert_create
- name: print ARN of cert we just created ansible.builtin.debug: var: cert_create.certificate.arn
- name: delete the cert we just created community.aws.aws_acm: name_tag: my_cert state: absent region: ap-southeast-2
- name: delete a certificate with a particular ARN community.aws.aws_acm: certificate_arn: "arn:aws:acm:ap-southeast-2:123456789012:certificate/01234567-abcd-abcd-abcd-012345678901" state: absent region: ap-southeast-2
- name: delete all certificates with a particular domain name community.aws.aws_acm: domain_name: acm.ansible.com state: absent region: ap-southeast-2
state: choices: - present - absent default: present description: - 'If I(state=present), the specified public certificate and private key will be uploaded, with I(Name) tag equal to I(name_tag). ' - 'If I(state=absent), any certificates in this region with a corresponding I(domain_name), I(name_tag) or I(certificate_arn) will be deleted. ' type: str region: aliases: - aws_region - ec2_region description: - The AWS region to use. - For global services such as IAM, Route53 and CloudFront, I(region) is ignored. - The C(AWS_REGION) or C(EC2_REGION) environment variables may also be used. - See the Amazon AWS documentation for more information U(http://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region). - The C(ec2_region) alias has been deprecated and will be removed in a release after 2024-12-01 - Support for the C(EC2_REGION) environment variable has been deprecated and will be removed in a release after 2024-12-01. type: str profile: aliases: - aws_profile description: - A named AWS profile to use for authentication. - See the AWS documentation for more information about named profiles U(https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html). - The C(AWS_PROFILE) environment variable may also be used. - The I(profile) option is mutually exclusive with the I(aws_access_key), I(aws_secret_key) and I(security_token) options. type: str name_tag: aliases: - name description: - The unique identifier for tagging resources using AWS tags, with key I(Name). - This can be any set of characters accepted by AWS for tag values. - 'This is to ensure Ansible can treat certificates idempotently, even though the ACM API allows duplicate certificates. ' - If I(state=preset), this must be specified. - 'If I(state=absent), you must provide exactly one of I(certificate_arn), I(domain_name) or I(name_tag). ' type: str access_key: aliases: - aws_access_key_id - aws_access_key - ec2_access_key description: - AWS access key ID. - See the AWS documentation for more information about access tokens U(https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys). - The C(AWS_ACCESS_KEY_ID), C(AWS_ACCESS_KEY) or C(EC2_ACCESS_KEY) environment variables may also be used in decreasing order of preference. - The I(aws_access_key) and I(profile) options are mutually exclusive. - The I(aws_access_key_id) alias was added in release 5.1.0 for consistency with the AWS botocore SDK. - The I(ec2_access_key) alias has been deprecated and will be removed in a release after 2024-12-01. - Support for the C(EC2_ACCESS_KEY) environment variable has been deprecated and will be removed in a release after 2024-12-01. type: str aws_config: description: - A dictionary to modify the botocore configuration. - Parameters can be found in the AWS documentation U(https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html#botocore.config.Config). type: dict secret_key: aliases: - aws_secret_access_key - aws_secret_key - ec2_secret_key description: - AWS secret access key. - See the AWS documentation for more information about access tokens U(https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys). - The C(AWS_SECRET_ACCESS_KEY), C(AWS_SECRET_KEY), or C(EC2_SECRET_KEY) environment variables may also be used in decreasing order of preference. - The I(secret_key) and I(profile) options are mutually exclusive. - The I(aws_secret_access_key) alias was added in release 5.1.0 for consistency with the AWS botocore SDK. - The I(ec2_secret_key) alias has been deprecated and will be removed in a release after 2024-12-01. - Support for the C(EC2_SECRET_KEY) environment variable has been deprecated and will be removed in a release after 2024-12-01. type: str certificate: description: - The body of the PEM encoded public certificate. - Required when I(state) is not C(absent). - If your certificate is in a file, use C(lookup('file', 'path/to/cert.pem')). type: str domain_name: aliases: - domain description: - The domain name of the certificate. - 'If I(state=absent) and I(domain_name) is specified, this task will delete all ACM certificates with this domain. ' - Exactly one of I(domain_name), I(name_tag) and I(certificate_arn) must be provided. - 'If I(state=present) this must not be specified. (Since the domain name is encoded within the public certificate''s body.) ' type: str private_key: description: - The body of the PEM encoded private key. - Required when I(state=present). - Ignored when I(state=absent). - If your private key is in a file, use C(lookup('file', 'path/to/key.pem')). type: str endpoint_url: aliases: - ec2_url - aws_endpoint_url - s3_url description: - URL to connect to instead of the default AWS endpoints. While this can be used to connection to other AWS-compatible services the amazon.aws and community.aws collections are only tested against AWS. - The C(AWS_URL) or C(EC2_URL) environment variables may also be used, in decreasing order of preference. - The I(ec2_url) and I(s3_url) aliases have been deprecated and will be removed in a release after 2024-12-01. - Support for the C(EC2_URL) environment variable has been deprecated and will be removed in a release after 2024-12-01. type: str aws_ca_bundle: description: - The location of a CA Bundle to use when validating SSL certificates. - The C(AWS_CA_BUNDLE) environment variable may also be used. type: path session_token: aliases: - aws_session_token - security_token - aws_security_token - access_token description: - AWS STS session token for use with temporary credentials. - See the AWS documentation for more information about access tokens U(https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys). - The C(AWS_SESSION_TOKEN), C(AWS_SECURITY_TOKEN) or C(EC2_SECURITY_TOKEN) environment variables may also be used in decreasing order of preference. - The I(security_token) and I(profile) options are mutually exclusive. - Aliases I(aws_session_token) and I(session_token) were added in release 3.2.0, with the parameter being renamed from I(security_token) to I(session_token) in release 6.0.0. - The I(security_token), I(aws_security_token), and I(access_token) aliases have been deprecated and will be removed in a release after 2024-12-01. - Support for the C(EC2_SECRET_KEY) and C(AWS_SECURITY_TOKEN) environment variables has been deprecated and will be removed in a release after 2024-12-01. type: str validate_certs: default: true description: - When set to C(false), SSL certificates will not be validated for communication with the AWS APIs. - Setting I(validate_certs=false) is strongly discouraged, as an alternative, consider setting I(aws_ca_bundle) instead. type: bool certificate_arn: aliases: - arn description: - The ARN of a certificate in ACM to delete - Ignored when I(state=present). - If I(state=absent), you must provide one of I(certificate_arn), I(domain_name) or I(name_tag). - 'If I(state=absent) and no resource exists with this ARN in this region, the task will succeed with no effect. ' - 'If I(state=absent) and the corresponding resource exists in a different region, this task may report success without deleting that resource. ' type: str certificate_chain: description: - The body of the PEM encoded chain for your certificate. - If your certificate chain is in a file, use C(lookup('file', 'path/to/chain.pem')). - Ignored when I(state=absent) type: str debug_botocore_endpoint_logs: default: false description: - Use a C(botocore.endpoint) logger to parse the unique (rather than total) C("resource:action") API calls made during a task, outputing the set to the resource_actions key in the task results. Use the C(aws_resource_action) callback to output to total list made during a playbook. - The C(ANSIBLE_DEBUG_BOTOCORE_LOGS) environment variable may also be used. type: bool
arns: description: A list of the ARNs of the certificates in ACM which were deleted elements: str returned: when I(state=absent) sample: - arn:aws:acm:ap-southeast-2:123456789012:certificate/01234567-abcd-abcd-abcd-012345678901 type: list certificate: contains: arn: description: The ARN of the certificate in ACM returned: when I(state=present) sample: arn:aws:acm:ap-southeast-2:123456789012:certificate/01234567-abcd-abcd-abcd-012345678901 type: str domain_name: description: The domain name encoded within the public certificate returned: when I(state=present) sample: acm.ansible.com type: str description: Information about the certificate which was uploaded returned: when I(state=present) type: complex