-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-config-cloudwatch.yml
58 lines (58 loc) · 2.08 KB
/
install-config-cloudwatch.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
- hosts: cloudwatch_machines
become: yes
become_method: sudo
tasks:
- name: copy .env file
become: yes
copy:
src: .env
dest: "/root/.env"
owner: root
group: root
mode: '0700'
- name: Get env file content
become: yes
no_log: true
slurp:
src: /root/.env
register: env_file_content
- name: Parse env file and load into fact
become: yes
set_fact:
env_vars: "{{ ('{' + (env_file_content.content | b64decode).split('\n') | select | map('regex_replace', '([^=]*)=(.*)', '\"\\1\": \"\\2\"') | join(',') + '}') | from_json }}"
- name: create AWS cred dir if it doesn't exist
file:
path: /root/.aws
state: directory
mode: '0700'
- name: create AWS config file
copy:
dest: /root/.aws/config
content: |
[AmazonCloudWatchAgent]
region={{ env_vars["AWS_REGION"] }}
- name: create AWS credentials file
copy:
dest: /root/.aws/credentials
content: |
[AmazonCloudWatchAgent]
aws_access_key_id={{ env_vars["AWS_ACCESS_KEY_ID"] }}
aws_secret_access_key={{ env_vars["AWS_SECRET_ACCESS_KEY"] }}
- name: install CloudWatch Agent
apt:
deb: https://s3.amazonaws.com/amazoncloudwatch-agent/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb
- name: check ansible_hostname
debug:
var: ansible_hostname
- name: copy over config file with log filtering for prospoero
copy:
src: CloudWatch/config_with_log.json
dest: /opt/aws/amazon-cloudwatch-agent/bin/config.json
when: ansible_hostname == "sycorax"
- name: copy over config file without log filtering for other servers
copy:
src: CloudWatch/config.json
dest: /opt/aws/amazon-cloudwatch-agent/bin/config.json
when: ansible_hostname != "sycorax"
- name: start the CloudWatch Agent
command: "/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m onPremise -s -c file:/opt/aws/amazon-cloudwatch-agent/bin/config.json"