From 58d8c6bf006cc26fbda40115ebe55852cb0894ff Mon Sep 17 00:00:00 2001 From: Justin Wind Date: Thu, 16 Mar 2017 10:38:31 -0700 Subject: [PATCH] add awslogs role --- roles/awslogs/files/awslogs.conf | 4 +++ roles/awslogs/files/logging.conf | 39 ++++++++++++++++++++++++ roles/awslogs/handlers/main.yml | 5 ++++ roles/awslogs/tasks/main.yml | 41 ++++++++++++++++++++++++++ roles/awslogs/templates/awscli.conf.j2 | 4 +++ 5 files changed, 93 insertions(+) create mode 100644 roles/awslogs/files/awslogs.conf create mode 100644 roles/awslogs/files/logging.conf create mode 100644 roles/awslogs/handlers/main.yml create mode 100644 roles/awslogs/tasks/main.yml create mode 100644 roles/awslogs/templates/awscli.conf.j2 diff --git a/roles/awslogs/files/awslogs.conf b/roles/awslogs/files/awslogs.conf new file mode 100644 index 0000000..e2cac13 --- /dev/null +++ b/roles/awslogs/files/awslogs.conf @@ -0,0 +1,4 @@ +[general] +state_file = /var/lib/awslogs/agent-state +logging_config_file = /etc/awslogs/logging.conf +use_gzip_http_content_encoding = true diff --git a/roles/awslogs/files/logging.conf b/roles/awslogs/files/logging.conf new file mode 100644 index 0000000..f41cfb6 --- /dev/null +++ b/roles/awslogs/files/logging.conf @@ -0,0 +1,39 @@ +[loggers] +keys=root,cwlogs,reader,publisher + +[handlers] +keys=consoleHandler + +[formatters] +keys=simpleFormatter + +[logger_root] +level=WARNING +handlers=consoleHandler + +[logger_cwlogs] +level=WARNING +handlers=consoleHandler +qualname=cwlogs.push +propagate=0 + +[logger_reader] +level=ERROR +handlers=consoleHandler +qualname=cwlogs.push.reader +propagate=0 + +[logger_publisher] +level=WARNING +handlers=consoleHandler +qualname=cwlogs.push.publisher +propagate=0 + +[handler_consoleHandler] +class=logging.StreamHandler +level=INFO +formatter=simpleFormatter +args=(sys.stderr,) + +[formatter_simpleFormatter] +format=%(asctime)s - %(name)s - %(levelname)s - %(process)d - %(threadName)s - %(message)s diff --git a/roles/awslogs/handlers/main.yml b/roles/awslogs/handlers/main.yml new file mode 100644 index 0000000..e90da80 --- /dev/null +++ b/roles/awslogs/handlers/main.yml @@ -0,0 +1,5 @@ +--- +- name: restart awslogs + service: + name: awslogs + state: restarted diff --git a/roles/awslogs/tasks/main.yml b/roles/awslogs/tasks/main.yml new file mode 100644 index 0000000..7fb354d --- /dev/null +++ b/roles/awslogs/tasks/main.yml @@ -0,0 +1,41 @@ +--- +- ec2_facts: + +- name: Install awslogs package + with_items: + - awslogs + yum: + name: "{{ item }}" + state: latest + +- name: Install awslogs templates + with_items: + - awscli.conf + template: + src: "{{ item }}.j2" + dest: /etc/awslogs/{{ item }} + mode: "0644" + owner: root + group: root + notify: + - restart awslogs + +- name: Install awslogs configs + with_items: + - awslogs.conf + - logging.conf + copy: + src: "{{ item }}" + dest: /etc/awslogs/{{ item }} + mode: "0644" + owner: root + group: root + notify: + - restart awslogs + +- name: enable awslogs + service: + name: awslogs + enabled: yes + notify: + - restart awslogs diff --git a/roles/awslogs/templates/awscli.conf.j2 b/roles/awslogs/templates/awscli.conf.j2 new file mode 100644 index 0000000..9c7137b --- /dev/null +++ b/roles/awslogs/templates/awscli.conf.j2 @@ -0,0 +1,4 @@ +[plugins] +cwlogs = cwlogs +[default] +region = {{ ansible_ec2_placement_region }} -- 2.45.2