Cloudwatch Agent Installation to EC2 Instances with Ansible


In this post, I will be explaining how to install Cloudwatch Agent using an Ansible Controller Host machine which is used for initializing and provisioning other machines.

You will need:

  • Basic knowledge of Ansible
  • A Controller machine to run the playbook remotely
  • A Controller machine with Ansible installed
  • A Remote machine with SSH Daemon and Python interpreter installed
  • A Remote machine with proper Policy attached (Allowance for PutMetricData)
  • Make sure you have a proper configuration .json file, check here


Using a Controller EC2 instance makes it easier to manage other instances since in this way, you don’t need to install Ansible each machine you manage because it works with SSH Daemon and an up-to-date Python interpreter.

You can run this playbook on your Controller machine with:

ansible-playbook -s configure-cloudwatch-agent.yml

In fact, you can use variables to configure different environments such as Development, Production etc. For example, we could define “/opt/aws” as our base_dir and call it
{{ base_dir }}.
Continue reading