ansible.builtin.cloudtrail (v2.6.10) — module

manage CloudTrail create, delete, update

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

Authors: Ansible Core Team, Ted Timmons, Daniel Shepherd (@shepdelacreme)

preview | supported by community

Install Ansible via pip

Install with pip install ansible==2.6.10

Description

Creates, deletes, or updates CloudTrail configuration. Ensures logging is also enabled.


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: create single region cloudtrail
  cloudtrail:
    state: present
    name: default
    s3_bucket_name: mylogbucket
    s3_key_prefix: cloudtrail
    region: us-east-1
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: create multi-region trail with validation and tags
  cloudtrail:
    state: present
    name: default
    s3_bucket_name: mylogbucket
    region: us-east-1
    is_multi_region_trail: true
    enable_log_file_validation: true
    cloudwatch_logs_role_arn: "arn:aws:iam::123456789012:role/CloudTrail_CloudWatchLogs_Role"
    cloudwatch_logs_log_group_arn: "arn:aws:logs:us-east-1:123456789012:log-group:CloudTrail/DefaultLogGroup:*"
    kms_key_id: "alias/MyAliasName"
    tags:
      environment: dev
      Name: default
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: show another valid kms_key_id
  cloudtrail:
    state: present
    name: default
    s3_bucket_name: mylogbucket
    kms_key_id: "arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
    # simply "12345678-1234-1234-1234-123456789012" would be valid too.

- name: pause logging the trail we just created
  cloudtrail:
    state: present
    name: default
    enable_logging: false
    s3_bucket_name: mylogbucket
    region: us-east-1
    is_multi_region_trail: true
    enable_log_file_validation: true
    tags:
      environment: dev
      Name: default
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: delete a trail
  cloudtrail:
    state: absent
    name: default

Inputs

    
name:
    description:
    - Name for the CloudTrail.
    - Names are unique per-region unless the CloudTrail is a multi-region trail, in which
      case it is unique per-account.
    required: true

tags:
    default: {}
    description:
    - A hash/dictionary of tags to be applied to the CloudTrail resource.
    - Remove completely or specify an empty dictionary to remove all tags.
    version_added: '2.4'
    version_added_collection: ansible.builtin

state:
    choices:
    - present
    - absent
    - enabled
    - disabled
    description:
    - Add or remove CloudTrail configuration.
    - The following states have been preserved for backwards compatibility. C(state=enabled)
      and C(state=disabled).
    - enabled=present and disabled=absent.
    required: true

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.  Prior to release 6.0.0
      the C(AWS_PROFILE) environment variable will be ignored if any of I(access_key),
      I(secret_key), or I(session_token) are passed.  After release 6.0.0 I(profile) will
      always fall back to the C(AWS_PROFILE) environment variable if set.
    - The I(profile) option is mutually exclusive with the I(aws_access_key), I(aws_secret_key)
      and I(security_token) options.
    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.  Prior to release 6.0.0 these
      environment variables will be ignored if the I(profile) parameter is passed.  After
      release 6.0.0 I(access_key) will always fall back to the environment variables if
      set.
    - 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

kms_key_id:
    description:
    - Specifies the KMS key ID to use to encrypt the logs delivered by CloudTrail. This
      also has the effect of enabling log file encryption.
    - The value can be an alias name prefixed by "alias/", a fully specified ARN to an
      alias, a fully specified ARN to a key, or a globally unique identifier.
    - See U(https://docs.aws.amazon.com/awscloudtrail/latest/userguide/encrypting-cloudtrail-log-files-with-aws-kms.html)
    version_added: '2.4'
    version_added_collection: ansible.builtin

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.  Prior to release
      6.0.0 these environment variables will be ignored if the I(profile) parameter is
      passed.  After release 6.0.0 I(secret_key) will always fall back to the environment
      variables if set.
    - 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

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

s3_key_prefix:
    description:
    - S3 Key prefix for delivered log files. A trailing slash is not necessary and will
      be removed.

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. Prior to release 6.0.0
      these environment variables will be ignored if the I(profile) parameter is passed.  After
      release 6.0.0 I(session_token) will always fall back to the environment variables
      if set.
    - 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

enable_logging:
    default: true
    description:
    - Start or stop the CloudTrail logging. If stopped the trail will be paused and will
      not record events or deliver log files.
    version_added: '2.4'
    version_added_collection: ansible.builtin

s3_bucket_name:
    description:
    - An existing S3 bucket where CloudTrail will deliver log files.
    - This bucket should exist and have the proper policy.
    - See U(http://docs.aws.amazon.com/awscloudtrail/latest/userguide/aggregating_logs_regions_bucket_policy.html)
    - Required when C(state=present)
    version_added: '2.4'
    version_added_collection: ansible.builtin

sns_topic_name:
    description:
    - SNS Topic name to send notifications to when a log file is delivered
    version_added: '2.4'
    version_added_collection: ansible.builtin

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

include_global_events:
    aliases:
    - include_global_service_events
    default: true
    description:
    - Record API calls from global services such as IAM and STS.

is_multi_region_trail:
    default: false
    description:
    - Specify whether the trail belongs only to one region or exists in all regions.
    version_added: '2.4'
    version_added_collection: ansible.builtin

cloudwatch_logs_role_arn:
    description:
    - Specifies a full ARN for an IAM role that assigns the proper permissions for CloudTrail
      to create and write to the log group.
    - See U(https://docs.aws.amazon.com/awscloudtrail/latest/userguide/send-cloudtrail-events-to-cloudwatch-logs.html)
    - Required when C(cloudwatch_logs_log_group_arn)
    version_added: '2.4'
    version_added_collection: ansible.builtin

enable_log_file_validation:
    aliases:
    - log_file_validation_enabled
    description:
    - Specifies whether log file integrity validation is enabled.
    - CloudTrail will create a hash for every log file delivered and produce a signed
      digest file that can be used to ensure log files have not been tampered.
    version_added: '2.4'
    version_added_collection: ansible.builtin

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

cloudwatch_logs_log_group_arn:
    description:
    - A full ARN specifying a valid CloudWatch log group to which CloudTrail logs will
      be delivered. The log group should already exist.
    - See U(https://docs.aws.amazon.com/awscloudtrail/latest/userguide/send-cloudtrail-events-to-cloudwatch-logs.html)
    - Required when C(cloudwatch_logs_role_arn)
    version_added: '2.4'
    version_added_collection: ansible.builtin

Outputs

exists:
  description: whether the resource exists
  returned: always
  sample: true
  type: bool
trail:
  contains:
    cloud_watch_logs_log_group_arn:
      description: Full ARN of the CloudWatch Logs log group where events are delivered.
      returned: success when present
      sample: arn:aws:logs:us-east-1:123456789012:log-group:CloudTrail/DefaultLogGroup:*
      type: string
    cloud_watch_logs_role_arn:
      description: Full ARN of the IAM role that CloudTrail assumes to deliver events.
      returned: success when present
      sample: arn:aws:iam::123456789012:role/CloudTrail_CloudWatchLogs_Role
      type: string
    has_custom_event_selectors:
      description: Whether any custom event selectors are used for this trail.
      returned: success
      sample: false
      type: bool
    home_region:
      description: The home region where the trail was originally created and must
        be edited.
      returned: success
      sample: us-east-1
      type: string
    include_global_service_events:
      description: Whether global services (IAM, STS) are logged with this trail
      returned: success
      sample: true
      type: bool
    is_logging:
      description: Whether logging is turned on or paused for the Trail
      returned: success
      sample: true
      type: bool
    is_multi_region_trail:
      description: Whether the trail applies to all regions or just one
      returned: success
      sample: true
      type: bool
    kms_key_id:
      description: Full ARN of the KMS Key used to encrypt log files.
      returned: success when present
      sample: arn:aws:kms::123456789012:key/12345678-1234-1234-1234-123456789012
      type: string
    log_file_validation_enabled:
      description: Whether log file validation is enabled on the trail
      returned: success
      sample: true
      type: bool
    name:
      description: Name of the CloudTrail resource
      returned: success
      sample: default
      type: string
    s3_bucket_name:
      description: S3 bucket name where log files are delivered
      returned: success
      sample: myBucket
      type: string
    s3_key_prefix:
      description: Key prefix in bucket where log files are delivered (if any)
      returned: success when present
      sample: myKeyPrefix
      type: string
    sns_topic_arn:
      description: Full ARN of the SNS topic where log delivery notifications are
        sent.
      returned: success when present
      sample: arn:aws:sns:us-east-1:123456789012:topic/myTopic
      type: string
    sns_topic_name:
      description: The SNS topic name where log delivery notifications are sent.
      returned: success when present
      sample: myTopic
      type: string
    tags:
      description: hash/dictionary of tags applied to this resource
      returned: success
      sample:
        Name: default
        environment: dev
      type: dict
    trail_arn:
      description: Full ARN of the CloudTrail resource
      returned: success
      sample: arn:aws:cloudtrail:us-east-1:123456789012:trail/default
      type: string
  description: CloudTrail resource details
  returned: always
  sample: hash/dictionary of values
  type: complex