christiangda / ansible-role-amazon-cloudwatch-agent

Ansible Role for Amazon Cloudwatch Agent
GNU General Public License v3.0
60 stars 45 forks source link

Leaving the Region Value out of amazon-cloudwatch-agent.json #24

Closed txynidakis closed 4 years ago

txynidakis commented 4 years ago

Hi This is my Scenario

We have a golden AMI pipeline in Region A where the CW-A role is used and then copy the AMI to Region B. We bake in the CW-A install to save on launch time.

If we set cwa_aws_region in the playbook in in Region A. Then when we launch the copied AMI in Region B, amazon-cloudwatch-agent.json configs still show the region from Region A.

From the documents https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-Configuration-File-Details.html, IF, the region is left out, then by DEFAULT the agent will send data to log region in which the EC2 was launch from.

For the moment I've got around the problem by creating a custom file and referenced

I've tried to have a play

# Remove Region settings from agent configuration file if we need to send data to the region the EC2 was created in
- name: Remove the region reference if None were specified
  lineinfile:
    path: "{{ cwa_agent_config_file }}/amazon-cloudwatch-agent.json"
    state: absent
    regexp: '*region*'
  when: >
    cwa_aws_region | lower == "none"

but couldn't get it working, (haven't spent that much time on it though) and it's probably not an ideal solution.

Can you recommend a way forward to remove the region value from the json file

Kind regards Tony

christiangda commented 4 years ago

Hi @txynidakis ,

Thank you for your very good explanation and details.

As soon as I can, I'll check your case in order to see how can I handle your case.

christiangda commented 4 years ago

Hi @txynidakis ,

Following your recommendation, I created a patch to support leave the cwa_aws_region empty by default, I tested it, and it is working. Right now I'm releasing the new version

christiangda commented 4 years ago

resolved in PR#28