-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d0d0cd7
commit c3fc87f
Showing
12 changed files
with
221 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
build | ||
Dockerfile.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
GIT_COMMIT=$(shell git rev-parse HEAD) | ||
MY_DIR=$(shell basename $(CURDIR)) | ||
TEST_LABEL_KEY=ansible-role-testing | ||
PLATFORM=ubuntu | ||
define DOCKER_BODY | ||
RUN apt-get update && apt-get install -y \\ | ||
gcc \\ | ||
git \\ | ||
python-dev \\ | ||
python-pip \\ | ||
libffi-dev \\ | ||
libssl-dev && \\ | ||
pip install -U distribute boto ansible==2.1.0 virtualenv awscli | ||
# ansible 2.1.0 fail: https://github.com/ansible/ansible/issues/16015 | ||
ARG ANSIBLE_OPTIONS | ||
ARG TEST_LABEL | ||
ARG TEST_LABEL_KEY | ||
ARG TEST_TAG | ||
ARG GIT_COMMIT=unknown | ||
LABEL $$TEST_LABEL_KEY=$$TEST_LABEL | ||
LABEL git-commit=$$GIT_COMMIT | ||
LABEL TEST_TAG=$$TEST_TAG | ||
ADD tests /tmp/playbook | ||
ADD . /tmp/playbook/roles/$$TEST_LABEL | ||
WORKDIR /tmp/playbook | ||
RUN ansible-playbook $$ANSIBLE_OPTIONS -i inventory test.yml -e environ=dev -e region=us-west-2 -e cw_alarms_action_arn=${CW_ALARMS_ACTION_ARN} | ||
endef | ||
export DOCKER_BODY | ||
|
||
%4: TEST_TAG = 14.04 | ||
%6: TEST_TAG = 16.04 | ||
|
||
.PHONY: default | ||
default: test16 | ||
|
||
testv%: ANSIBLE_OPTIONS = -v | ||
test%: | ||
( echo 'FROM ${PLATFORM}:${TEST_TAG}' ) > tests/Dockerfile.${PLATFORM}.${TEST_TAG} | ||
echo "$$DOCKER_BODY" >> tests/Dockerfile.${PLATFORM}.${TEST_TAG} | ||
docker build --build-arg TEST_LABEL=${MY_DIR} \ | ||
--build-arg TEST_LABEL_KEY=${TEST_LABEL_KEY} \ | ||
--build-arg GIT_COMMIT=${GIT_COMMIT} \ | ||
--build-arg TEST_TAG=${TEST_TAG} \ | ||
--build-arg ANSIBLE_OPTIONS=${ANSIBLE_OPTIONS} \ | ||
--force-rm -t ${MY_DIR}:${TEST_TAG} -f tests/Dockerfile.${PLATFORM}.${TEST_TAG} . | ||
remove%: | ||
docker rmi $(shell docker images -q --filter label=TEST_TAG=${TEST_TAG} --filter label=${TEST_LABEL_KEY}=${MY_DIR}) | ||
rm tests/Dockerfile.${PLATFORM}.${TEST_TAG} | ||
clean .IGNORE: remove14 remove16 | ||
all: test14 test16 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
cw_alarms_build_dir: "{{ playbook_dir }}/build" | ||
cw_alarms_template_dir: "{{ cw_alarms_build_dir }}" | ||
cw_alarms_template_name: "{{ cw_alarms_stack_name }}.json" | ||
cw_alarms_stack_state: present | ||
cw_alarms_region: "{{ region | default('us-west-2') }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[localhost] | ||
localhost ansible_connection=local ansible_python_interpreter=python |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
dependencies: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
- name: Create necessary directories | ||
file: | ||
state: directory | ||
path: "{{ item }}" | ||
with_items: | ||
- "{{ cw_alarms_build_dir }}" | ||
- "{{ cw_alarms_template_dir }}" | ||
|
||
- name: Template alarms | ||
template: | ||
src: cloudwatch.json.j2 | ||
dest: "{{ cw_alarms_template_dir }}/{{ cw_alarms_template_name }}" | ||
|
||
|
||
- shell: "cat {{ cw_alarms_template_dir }}/{{ cw_alarms_template_name }}" | ||
|
||
|
||
- name: Deploy alarms | ||
cloudformation: | ||
template: "{{ cw_alarms_template_dir }}/{{ cw_alarms_template_name }}" | ||
region: "{{ cw_alarms_region }}" | ||
stack_name: "{{ cw_alarms_stack_name }}" | ||
state: "{{ cw_alarms_stack_state }}" | ||
security_token: "{{ ansible_security_token | default(omit, true) }}" | ||
region: "{{ cw_alarms_stack_region }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
{ | ||
"AWSTemplateFormatVersion" : "2010-09-09", | ||
"Resources" : { | ||
{% for alarm in cw_alarms %} | ||
"{{ alarm.name }}": { | ||
"Type": "AWS::CloudWatch::Alarm", | ||
"Properties": { | ||
"AlarmDescription": "{{ alarm.description | default('') }}", | ||
"Namespace": "{{ alarm.namespace }}", | ||
"MetricName": "{{ alarm.metric }}", | ||
"Dimensions": [ | ||
{% for dimension in alarm.dimensions %} | ||
{ | ||
"Name": "{{ dimension.name }}", | ||
"Value" : "{{ dimension.value }}" | ||
} | ||
{% if not loop.last %}, {% endif %} | ||
{% endfor %} | ||
], | ||
"Statistic": "{{ alarm.statistic }}", | ||
"Period": "{{ alarm.period_length }}", | ||
"EvaluationPeriods": "{{ alarm.eval_periods }}", | ||
"Threshold": "{{ alarm.threshold }}", | ||
"ComparisonOperator": "{{ alarm.comparison_operator }}" | ||
{% if alarm.unit is defined %} | ||
, | ||
"Unit" : "{{ alarm.unit }}" | ||
{% endif %} | ||
{% if alarm.actions is defined or cw_alarms_stack_actions is defined %} | ||
, | ||
"AlarmActions": [ | ||
{% if alarm.actions is defined %} | ||
{% for arn in alarm.actions %} | ||
"{{ arn }}" | ||
{% if not loop.last %}, {% endif %} | ||
{% endfor %} | ||
{% if cw_alarms_stack_actions is defined %},{% endif %} | ||
{% endif %} | ||
{% if cw_alarms_stack_actions is defined %} | ||
{% for arn in cw_alarms_stack_actions %} | ||
"{{ arn }}" | ||
{% if not loop.last %}, {% endif %} | ||
{% endfor %} | ||
{% endif %} | ||
] | ||
{% endif %} | ||
{% if alarm.insufficient_data_actions is defined %} | ||
, | ||
"InsufficientDataActions": [ | ||
{% for action_arn in alarm.insufficient_data_actions %} | ||
{{ action_arn }} | ||
{% endfor %} | ||
] | ||
{% endif %} | ||
} | ||
} | ||
{% if not loop.last %}, {% endif %} | ||
{% endfor %} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[test] | ||
localhost ansible_connection=local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
- hosts: test | ||
vars: | ||
cw_alarms_stack_name: ansible-role-cfn-cloudwatch-alarms-testing | ||
cw_alarms: | ||
- name: "MemoryUtilizationAlarm" | ||
namespace: "System/Linux" | ||
metric: "MemoryUtilization" | ||
eval_periods: 1 | ||
statistic: "Minimum" | ||
threshold: 10 | ||
unit: "Percent" | ||
period_length: 60 | ||
comparison_operator: "GreaterThanOrEqualToThreshold" | ||
actions: | ||
- "{{ cw_alarms_action_arn }}" | ||
dimensions: | ||
- name: "AppName" | ||
value: "TestCustomMetric" | ||
# ansible_security_token: "{{ lookup('env','AWS_SESSION_TOKEN') }}" | ||
roles: | ||
- ansible-role-cfn-cloudwatch-alarms |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
- hosts: test | ||
vars: | ||
cw_alarms_stack_name: ansible-role-cfn-cloudwatch-alarms-testing | ||
cw_alarms_stack_actions: | ||
- "{{ cw_alarms_action_arn }}" | ||
|
||
cw_alarms: | ||
- name: "MemoryUtilizationAlarm" | ||
namespace: "System/Linux" | ||
metric: "MemoryUtilization" | ||
eval_periods: 1 | ||
statistic: "Minimum" | ||
threshold: 10 | ||
unit: "Percent" | ||
period_length: 60 | ||
comparison_operator: "GreaterThanOrEqualToThreshold" | ||
dimensions: | ||
- name: "AppName" | ||
value: "TestCustomMetric" | ||
# ansible_security_token: "{{ lookup('env','AWS_SESSION_TOKEN') }}" | ||
roles: | ||
- ansible-role-cfn-cloudwatch-alarms |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
- hosts: test | ||
vars: | ||
cw_alarms_stack_name: ansible-role-cfn-cloudwatch-alarms-testing | ||
cw_alarms_stack_actions: | ||
- "{{ cw_alarms_action_arn }}" | ||
|
||
cw_alarms: | ||
- name: "MemoryUtilizationAlarm" | ||
namespace: "System/Linux" | ||
metric: "MemoryUtilization" | ||
eval_periods: 1 | ||
statistic: "Minimum" | ||
threshold: 10 | ||
unit: "Percent" | ||
period_length: 60 | ||
comparison_operator: "GreaterThanOrEqualToThreshold" | ||
actions: | ||
- "{{ cw_alarms_action_arn }}" | ||
dimensions: | ||
- name: "AppName" | ||
value: "TestCustomMetric" | ||
# ansible_security_token: "{{ lookup('env','AWS_SESSION_TOKEN') }}" | ||
roles: | ||
- ansible-role-cfn-cloudwatch-alarms |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
- include: per_alarm_actions.yml | ||
- include: per_alarm_actions.yml cw_alarms_stack_state=absent | ||
- include: per_stack_actions.yml | ||
- include: per_stack_actions.yml cw_alarms_stack_state=absent | ||
- include: per_stack_and_alarm_actions.yml | ||
- include: per_stack_and_alarm_actions.yml cw_alarms_stack_state=absent |