community.aws.aws_acm (3.4.0) — module

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 Limited

Install collection

Install with ansible-galaxy collection install community.aws:==3.4.0


Add to requirements.yml

  collections:
    - name: community.aws
      version: 3.4.0

Description

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.


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.

- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: create/update a certificate with a chain
  community.aws.aws_acm:
    certificate: "{{ lookup('file', 'cert.pem' ) }}"
    private_key: "{{ lookup('file', 'key.pem' ) }}"
    name_tag: my_cert
    certificate_chain: "{{ lookup('file', 'chain.pem' ) }}"
    state: present
    region: ap-southeast-2
  register: cert_create
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: print ARN of cert we just created
  ansible.builtin.debug:
    var: cert_create.certificate.arn
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: delete the cert we just created
  community.aws.aws_acm:
    name_tag: my_cert
    state: absent
    region: ap-southeast-2
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: delete all certificates with a particular domain name
  community.aws.aws_acm:
    domain_name: acm.ansible.com
    state: absent
    region: ap-southeast-2
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: add tags to an existing certificate with a particular ARN
  community.aws.aws_acm:
    certificate_arn: "arn:aws:acm:ap-southeast-2:123456789012:certificate/01234567-abcd-abcd-abcd-012345678901"
    tags:
      Name: my_certificate
      Application: search
      Environment: development
    purge_tags: true

Inputs

    
tags:
    description:
    - Tags to apply to certificates imported in ACM.
    - 'If both I(name_tag) and the ''Name'' tag in I(tags) are set, the values must be
      the same.

      '
    - 'If the ''Name'' tag in I(tags) is not set and I(name_tag) is set, the I(name_tag)
      value is copied to I(tags).

      '
    type: dict
    version_added: 3.2.0
    version_added_collection: community.aws

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. If not specified then the value of the AWS_REGION or EC2_REGION
      environment variable, if any, is used. See U(http://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region)
    type: str

ec2_url:
    aliases:
    - aws_endpoint_url
    - endpoint_url
    description:
    - URL to use to connect to EC2 or your Eucalyptus cloud (by default the module will
      use EC2 endpoints). Ignored for modules where region is required. Must be specified
      for all other modules if region is not used. If not set then the value of the EC2_URL
      environment variable, if any, is used.
    type: str

profile:
    aliases:
    - aws_profile
    description:
    - Using I(profile) will override I(aws_access_key), I(aws_secret_key) and I(security_token)
      and support for passing them at the same time as I(profile) has been deprecated.
    - I(aws_access_key), I(aws_secret_key) and I(security_token) will be made mutually
      exclusive with I(profile) after 2022-06-01.
    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) and I(name_tag) is specified, this task will delete all ACM
      certificates with this Name tag.

      '
    - 'If I(state=absent), you must provide exactly one of I(certificate_arn), I(domain_name)
      or I(name_tag).

      '
    type: str

aws_config:
    description:
    - A dictionary to modify the botocore configuration.
    - Parameters can be found at U(https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html#botocore.config.Config).
    - Only the 'user_agent' key is used for boto modules. See U(http://boto.cloudhackers.com/en/latest/boto_config_tut.html#boto)
      for more boto configuration.
    type: dict

purge_tags:
    default: false
    description:
    - whether to remove tags not present in the C(tags) parameter.
    type: bool
    version_added: 3.2.0
    version_added_collection: community.aws

certificate:
    description:
    - The body of the PEM encoded public certificate.
    - Required when I(state) is not C(absent) and the certificate does not exist.
    - '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) and the certificate does not exist.
    - Ignored when I(state=absent).
    - 'If your private key is in a file, use C(lookup(''file'', ''path/to/key.pem'')).

      '
    type: str

aws_ca_bundle:
    description:
    - The location of a CA Bundle to use when validating SSL certificates.
    - Not used by boto 2 based modules.
    - 'Note: The CA Bundle is read ''module'' side and may need to be explicitly copied
      from the controller if not run locally.'
    type: path

aws_access_key:
    aliases:
    - ec2_access_key
    - access_key
    description:
    - C(AWS access key). If not set then the value of the C(AWS_ACCESS_KEY_ID), C(AWS_ACCESS_KEY)
      or C(EC2_ACCESS_KEY) environment variable is used.
    - If I(profile) is set this parameter is ignored.
    - Passing the I(aws_access_key) and I(profile) options at the same time has been deprecated
      and the options will be made mutually exclusive after 2022-06-01.
    type: str

aws_secret_key:
    aliases:
    - ec2_secret_key
    - secret_key
    description:
    - C(AWS secret key). If not set then the value of the C(AWS_SECRET_ACCESS_KEY), C(AWS_SECRET_KEY),
      or C(EC2_SECRET_KEY) environment variable is used.
    - If I(profile) is set this parameter is ignored.
    - Passing the I(aws_secret_key) and I(profile) options at the same time has been deprecated
      and the options will be made mutually exclusive after 2022-06-01.
    type: str

security_token:
    aliases:
    - aws_security_token
    - access_token
    description:
    - C(AWS STS security token). If not set then the value of the C(AWS_SECURITY_TOKEN)
      or C(EC2_SECURITY_TOKEN) environment variable is used.
    - If I(profile) is set this parameter is ignored.
    - Passing the I(security_token) and I(profile) options at the same time has been deprecated
      and the options will be made mutually exclusive after 2022-06-01.
    type: str

validate_certs:
    default: true
    description:
    - When set to "no", SSL certificates will not be validated for communication with
      the AWS APIs.
    type: bool

certificate_arn:
    aliases:
    - arn
    description:
    - The ARN of a certificate in ACM to modify or delete.
    - 'If I(state=present), the certificate with the specified ARN can be updated. For
      example, this can be used to add/remove tags to an existing certificate.

      '
    - '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: 'no'
    description:
    - Use a botocore.endpoint logger to parse the unique (rather than total) "resource:action"
      API calls made during a task, outputing the set to the resource_actions key in the
      task results. Use the aws_resource_action callback to output to total list made
      during a playbook. The ANSIBLE_DEBUG_BOTOCORE_LOGS environment variable may also
      be used.
    type: bool

Outputs

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) and not in check mode
      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