gavika.aws_cloudwatchagent

Ansible Role: AWS CloudWatch Agent

This Ansible role sets up and configures the AWS CloudWatch Agent on AWS EC2 instances and on-premise servers.

Requirements

  • An AWS EC2 instance or a Linux server in your own data center.
  • If using an EC2 instance, it needs to have an IAM role attached with permissions to run the AWS CloudWatch Agent. You can use the AWS pre-made policy called CloudWatchAgentServerPolicy.
  • If using a server in your own data center, set up /root/.aws/credentials and /root/.aws/config.
  • Provide the YAML variable aws_cloudwatch_agent_config. This will be changed into JSON format. For a basic setup, check defaults/main.yml.

Role Variables

Variable Default Value Description Required?
aws_cloudwatch_agent_username The admin user who owns the downloaded files. Usually the same as remote_user. Common names are ubuntu for Ubuntu, centos for CentOS, and ec2-user for Amazon Linux. If not provided, the role tries to guess based on the operating system. No
aws_cloudwatch_agent_download_directory The folder where the AWS CloudWatch Agent software will be downloaded. The role tries to figure this out based on the operating system if not provided. No
aws_cloudwatch_agent_download_url The link to download the Amazon CloudWatchAgent. This is set automatically by the role, but you can change it if needed. No
aws_cloudwatch_agent_mode ec2 The mode of the AWS CloudWatch Agent. It can be ec2, onPremise, or auto. No

Example JSON file: aws-cw-config.json

agent:
    metrics_collection_interval: 60
    run_as_user: "cwagent"
metrics:
    namespace: "Gavika"
    append_dimensions:
      InstanceId: "${aws:InstanceId}"
    metrics_collected:
      disk:
        measurement:
          - used_percent
        metrics_collection_interval: 60
        resources:
          - "*"
      mem:
        measurement:
          - mem_used_percent
        metrics_collection_interval: 60

Example of /root/.aws/credentials for a server in your own data center:

[AmazonCloudWatchAgent]
aws_access_key_id = your_access_key_id
aws_secret_access_key = your_secret_access_key

Example of /root/.aws/config for a server in your own data center:

[AmazonCloudWatchAgent]
region = us-east-1

For a list of metrics, check the AWS CloudWatchAgent Documentation.

Example Playbook

    - hosts: cloudwatch-servers
      roles:
         - role: Gavika.aws-cloudwatch-agent

Continuous Integration

You can run Molecule tests on your local machine.

License

Apache2

Author Information

Sudheer Satyanarayana

Gavika

Informazioni sul progetto

Install and configure AWS CloudWatch Agent

Installa
ansible-galaxy install gavika.aws_cloudwatchagent
Licenza
Unknown
Download
285