Skip to content

Commit

Permalink
Ensure app-specific CloudWatch configs are appended after agent restart
Browse files Browse the repository at this point in the history
  • Loading branch information
marcransome committed May 6, 2021
1 parent 7038672 commit 1d296c7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion roles/deploy/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ cloudwatch_agent:
metrics_collection_interval: 60
user: cwagent

tuxedo_log_default_parent: /var/log/tuxedo
tuxedo_logs_path: /var/log/tuxedo

tuxedo_log_files:
ewf:
Expand Down
10 changes: 3 additions & 7 deletions roles/deploy/tasks/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

- name: "{{ tuxedo_user }} : Create service logs directory"
file:
path: "/var/log/tuxedo/{{ tuxedo_user }}"
path: "{{ tuxedo_logs_path }}/{{ tuxedo_user }}"
owner: "{{ tuxedo_user }}"
group: "{{ tuxedo_user }}"
mode: 0755
Expand All @@ -50,7 +50,7 @@
- name: "{{ tuxedo_user }} : Populate template config files"
template:
src: "{{ item }}"
dest: "{{ new_deployment_files.path }}/config//{{ item | basename | replace('.j2', '') }}"
dest: "{{ new_deployment_files.path }}/config/{{ item | basename | replace('.j2', '') }}"
owner: "{{ tuxedo_user }}"
group: "{{ tuxedo_user }}"
mode: 0644
Expand Down Expand Up @@ -171,13 +171,9 @@
- name: "{{ tuxedo_user }} : Create CloudWatch agent configuration file for Tuxedo service group"
template:
src: templates/cloudwatch-config-service.json.j2
dest: "{{ cloudwatch_agent.config_dir }}//cloudwatch-config-{{ tuxedo_user }}.json"
dest: "{{ cloudwatch_agent.config_dir }}/cloudwatch-config-{{ tuxedo_user }}.json"
trim_blocks: False

- name: "{{ tuxedo_user }} : Add configuration for Tuxedo service group to CloudWatch agent"
command:
cmd: "{{ cloudwatch_agent.path }} -a append-config -m ec2 -s -c file:{{ cloudwatch_agent.config_dir }}//cloudwatch-config-{{ tuxedo_user }}.json"

- name: "{{ tuxedo_user }} : Start Tuxedo services"
become_user: "{{ tuxedo_user }}"
shell: "source $HOME/deployment/config/envfile && tmboot -y"
Expand Down
17 changes: 14 additions & 3 deletions roles/deploy/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
cloudwatch_log_stream_name: "{{ ansible_ec2_instance_id }}_{{ ansible_ec2_hostname }}"
region: "{{ ansible_ec2_instance_identity_document_region }}"

- name: Create CloudWatch agent configuration file for instance
- name: Create CloudWatch agent primary configuration file
template:
src: templates/cloudwatch-config.json.j2
dest: "{{ cloudwatch_agent.config_dir }}/cloudwatch-config.json"
Expand Down Expand Up @@ -67,9 +67,9 @@
group: "{{ tuxedo_service_group }}"
mode: 0755

- name: "Create logs directory"
- name: "Create Tuxedo logs directory"
file:
path: "/var/log/tuxedo"
path: "{{ tuxedo_logs_path }}"
owner: root
group: "{{ tuxedo_service_group }}"
mode: 0755
Expand All @@ -80,6 +80,17 @@
loop_control:
loop_var: tuxedo_user

- name: Find application-specific CloudWatch configuration files
find:
paths: "{{ cloudwatch_agent.config_dir }}"
patterns: 'cloudwatch-config-*.json'
register: cloudwatch_configs

- name: "{{ tuxedo_user }} : Add configuration for Tuxedo service group to CloudWatch agent"
command:
cmd: "{{ cloudwatch_agent.path }} -a append-config -m ec2 -s -c file:{{ item.path }}"
loop: "{{ cloudwatch_configs.files }}"

- name: Remove temporary directories
file:
path: "{{ application_artefact_files.path }}"
Expand Down
2 changes: 1 addition & 1 deletion roles/deploy/templates/cloudwatch-config-service.json.j2
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{% if tuxedo_user in tuxedo_log_files -%}
{%+ for log in tuxedo_log_files[tuxedo_user] -%}
{
"file_path": "{{ log.file_path_parent | default(tuxedo_log_default_parent) }}/{{ tuxedo_user }}/{{ log.file_pattern }}",
"file_path": "{{ tuxedo_logs_path }}/{{ tuxedo_user }}/{{ log.file_pattern }}",
"log_group_name": "{{ log.cloudwatch_log_group_name }}",
"log_stream_name": "{{ cloudwatch_log_stream_name }}"
}{%- if not loop.last -%},{%- endif -%}
Expand Down

0 comments on commit 1d296c7

Please sign in to comment.