tartansandal.awslogs-setup
awslogs-setup
This guide helps you set up the AWS CloudWatch Logs Agent from the beginning.
Instead of using the awslogs-agent-setup.py
script like other roles, this setup breaks it down into different files, templates, and ansible tasks. You can run these to get the same results without interaction.
This approach helps to separate the installation of the agent from its configuration. The configuration will be unique to your system and should likely be handled by a separate role that depends on awslogs-setup
(see below).
A copy of the original awslogs-agent-setup.py script
is included in the /src
directory for reference.
Requirements
This setup is intended for EC2 Linux instances running on AWS.
Role Variables
You will need to specify the AWS region for the installed aws-cli
. By default, it's set to:
awslogs_setup_region: ap-southeast-2
The setup installs a "launcher" script and a "nanny" script that keeps the agent running. You’ll need to provide a few system command paths. The following defaults should work on most systems:
awslogs_setup_launcher_nice: /usr/bin/nice
awslogs_setup_nanny_ps: /usr/bin/ps
awslogs_setup_nanny_cat: /usr/bin/cat
awslogs_setup_nanny_grep: /usr/bin/grep
awslogs_setup_nanny_service: /usr/sbin/service
Feel free to change these if your system is different.
Example Playbook
This role only installs the awslogs agent. You will set up the agent’s configuration based on your specific needs. Here’s a simple example:
- hosts: servers
vars:
awslogs_setup_region: us-east-1 # or set this in your inventory
roles:
- tartansandal.awslogs-setup
handlers:
- name: restart awslogs
service: awslogs state=restarted
post_tasks:
- name: configure awslogs for system log files
template:
src: awslogs.conf.j2
dest: /var/awslogs/etc/awslogs.conf
notify: restart awslogs
# Use the /var/awslogs/etc/config/ directory for specific service configurations
- name: configure awslogs for nginx log files
template:
src: nginx-awslogs.conf.j2
dest: /var/awslogs/etc/config/nginx.conf
notify: restart awslogs
You can move the post_tasks
section into separate roles that depend on awslogs-setup
.
For more details on configuring the agent, check the AWS documentation at http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/AgentReference.html.
ToDo
- Create a systemd configuration to manage the launcher script.
License
This guide is under the BSD license.