Skip to content

Commit

Permalink
Merge pull request #42 from christiangda/fix-issue#39
Browse files Browse the repository at this point in the history
Fixed issue#39 and issue#37
  • Loading branch information
christiangda committed Apr 8, 2022
2 parents 4a06fdd + dcdb21a commit cc03b2e
Show file tree
Hide file tree
Showing 25 changed files with 179 additions and 119 deletions.
7 changes: 7 additions & 0 deletions README.md
Expand Up @@ -19,6 +19,7 @@ The repository code is [https://github.com/christiangda/ansible-role-amazon-clou
* Provides a default [agent configuration](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-Configuration-File-Details.html) file (a minimal configuration, It is not recommended)
* Rotate CloudWatch Agent Log file
* **Allow you to load your own [JSON file](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-Configuration-File-Details.html) / YAML file or INLINE configuration for agent, metrics and logs sections**
* Support `amd64` and `arm64` architectures

**Notes:**

Expand All @@ -40,6 +41,9 @@ This role work on RedHat, CentOS, Amazon Linux, Debian and Ubuntu distributions
* CentOS
* 7
* 8
* stream8
* Rocky Linux
* 8
* Amazon Linux
* 2
* Ubuntu
Expand All @@ -49,8 +53,10 @@ This role work on RedHat, CentOS, Amazon Linux, Debian and Ubuntu distributions
* 20.*
* 21.*
* Debian
* Stretch (9)
* buster (10)
* bullseye (11)
* Bookworm (12)

To see the compatibility matrix of Python vs. Ansible versions see [Travis-CI build matrix](https://travis-ci.org/christiangda/ansible-role-amazon-cloudwatch-agent)

Expand All @@ -69,6 +75,7 @@ To see the compatibility matrix of Python vs. Ansible versions see [Travis-CI bu
| cwa_no_proxy | "169.254.169.254" |
| cwa_logrotate_file_size | "10M" |
| cwa_logrotate_files | 5 |
| cwa_debug | false |

**More Details:** See the file [defaults/main.yaml](defaults/main.yaml)

Expand Down
10 changes: 6 additions & 4 deletions defaults/main.yml
Expand Up @@ -109,7 +109,9 @@ cwa_logrotate_file_size: "10M"
# default value: 5
cwa_logrotate_files: 5

cwa_arch_names: {
"x86_64": "amd64",
"aarch64": "arm64"
}
# description: Enable the debug messages
# possible values:
# - true
# - false
# default value: false
cwa_debug: false
3 changes: 2 additions & 1 deletion meta/main.yml
Expand Up @@ -26,9 +26,10 @@ galaxy_info:
- bullseye
- name: Ubuntu
version:
- xenial
- bionic
- focal
- hirsute
- impish

galaxy_tags:
- aws
Expand Down
70 changes: 48 additions & 22 deletions molecule/vagrant/molecule.yml
Expand Up @@ -18,30 +18,56 @@ scenario:
name: vagrant

platforms:
- name: centos-8
box: centos/8
# - name: rockylinux-8
# #box: rockylinux/8
# box: generic/rocky8
# memory: 512
# cpus: 1
# - name: centos-7
# box: centos/7
# memory: 512
# cpus: 1
# - name: centos-8
# box: centos/8
# memory: 512
# cpus: 1
- name: centos-stream8
box: centos/stream8
memory: 512
cpus: 1
# - name: ubuntu-21.04
# box: generic/ubuntu2104
# memory: 1024
- name: ubuntu-20.04
box: generic/ubuntu2004
memory: 1024
# - name: ubuntu-16.04
# box: generic/ubuntu1604
# memory: 1024
# - name: ubuntu-18.04
# box: generic/ubuntu1804
# memory: 1024
# - name: amazonlinux-2
# box: gbailey/amzn2
# memory: 512
# cpus: 1
# - name: debian-12
# box: debian/bookworm64
# memory: 512
# cpus: 1
# - name: debian-11
# box: debian/bullseye64
# memory: 512
# cpus: 1
- name: debian-10
box: debian/buster64
memory: 512
# - name: centos-7
# box: centos/7
# memory: 512
# cpus: 1
# - name: amazonlinux-2
# box: gbailey/amzn2
# memory: 512
# cpus: 1
# - name: ubuntu-18.04
# box: ubuntu/bionic64
# memory: 512
# cpus: 1
# - name: debian-10
# box: debian/buster64
# memory: 512
# cpus: 1
# - name: debian-9
# box: debian/stretch64
# memory: 512
# cpus: 1
cpus: 1
# - name: debian-9
# box: debian/stretch64
# memory: 512
# cpus: 1
# - name: debian-8
# box: debian/jessie64
# memory: 512
# cpus: 1
17 changes: 10 additions & 7 deletions tasks/install-redhat.yml
Expand Up @@ -43,7 +43,7 @@

- name: Install {{ cwa_package }} dependencies (it depend on EPEL Repositories, you ned to take care of that)
block:
- name: Install "{{ cwa_dependencies_packages }}" dependency on Amazon 1/2
- name: Install {{ cwa_dependencies_packages }} dependency on Amazon 1/2
yum:
name: "{{ cwa_dependencies_packages }}"
state: present
Expand All @@ -57,7 +57,7 @@
tags:
- install

- name: Install "{{ cwa_dependencies_packages }}" dependency on ReHat/CentOS 6/7/8
- name: Install {{ cwa_dependencies_packages }} dependency on {{ansible_distribution}} 6/7/8
yum:
name: "{{ cwa_dependencies_packages }}"
state: present
Expand All @@ -68,7 +68,8 @@
when: >
ansible_os_family == 'RedHat' and (
ansible_distribution == 'CentOS' or
ansible_distribution == 'RedHat'
ansible_distribution == 'RedHat' or
ansible_distribution == 'Rocky'
) and (
ansible_distribution_major_version == '8' or
ansible_distribution_major_version == '7' or
Expand All @@ -94,7 +95,7 @@
tags:
- install

- name: Install {{ cwa_package }}.rpm on ReHat/CentOS 6/7
- name: Install {{ cwa_package }}.rpm on {{ansible_distribution}} 6/7
yum:
name: "{{ cwa_temp_path }}/{{ cwa_package }}.rpm"
disable_gpg_check: true
Expand All @@ -106,7 +107,8 @@
when: >
ansible_os_family == 'RedHat' and (
ansible_distribution == 'CentOS' or
ansible_distribution == 'RedHat'
ansible_distribution == 'RedHat' or
ansible_distribution == 'Rocky'
) and (
ansible_distribution_major_version == '7' or
ansible_distribution_major_version == '6'
Expand All @@ -115,7 +117,7 @@
tags:
- install

- name: Install {{ cwa_package }}.rpm on ReHat/CentOS 8
- name: Install {{ cwa_package }}.rpm on {{ansible_distribution}} 8
dnf:
name: "{{ cwa_temp_path }}/{{ cwa_package }}.rpm"
disable_gpg_check: true
Expand All @@ -127,7 +129,8 @@
when: >
ansible_os_family == 'RedHat' and (
ansible_distribution == 'CentOS' or
ansible_distribution == 'RedHat'
ansible_distribution == 'RedHat' or
ansible_distribution == 'Rocky'
) and
ansible_distribution_major_version == '8'
ignore_errors: "{{ ansible_check_mode }}"
Expand Down
112 changes: 27 additions & 85 deletions tasks/main.yml
Expand Up @@ -4,109 +4,51 @@
# https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/verify-CloudWatch-Agent-Package-Signature.html

# debug
# - name: check ansible_distribution_major_version
# debug: msg="ansible_distribution_major_version = {{ ansible_distribution_major_version }}"
- name: check ansible_os_family
debug: msg="ansible_os_family = {{ ansible_os_family }}"
when: cwa_debug

# - name: check ansible_distribution_release
# debug: msg="ansible_distribution_release = {{ ansible_distribution_release }}"
- name: check ansible_distribution
debug: msg="ansible_distribution = {{ ansible_distribution }}"
when: cwa_debug

# - name: check ansible_virtualization_type
# debug: msg="ansible_virtualization_type = {{ ansible_virtualization_type }}"
- name: check ansible_distribution_major_version
debug: msg="ansible_distribution_major_version = {{ ansible_distribution_major_version }}"
when: cwa_debug

- name: Set AWS architecture name
set_fact:
cwa_arch_name: "{{ cwa_arch_names.get(ansible_architecture) }}"

# Selective include of vars
- name: Include variables for RHEL
include_vars: "{{ item }}"
with_first_found:
- "redhat.yml"
- "main.yml"
when: >
ansible_os_family == 'RedHat' and
ansible_distribution == 'RedHat'
and (
ansible_distribution_major_version == '8' or
ansible_distribution_major_version == '7' or
ansible_distribution_major_version == '6'
)
tags:
- include-redhat-vars
- name: check ansible_distribution_release
debug: msg="ansible_distribution_release = {{ ansible_distribution_release }}"
when: cwa_debug

- name: Include variables for CentOS
include_vars: "{{ item }}"
with_first_found:
- "centos.yml"
- "main.yml"
when: >
ansible_os_family == 'RedHat' and
ansible_distribution == 'CentOS'
and (
ansible_distribution_major_version == '8' or
ansible_distribution_major_version == '7' or
ansible_distribution_major_version == '6'
)
tags:
- include-centos-vars

- name: Include variables for Amazon Linux
include_vars: "{{ item }}"
with_first_found:
- "amazon.yml"
- "main.yml"
when: >
ansible_os_family == 'RedHat' and
ansible_distribution == 'Amazon'
tags:
- include-amazon-vars
- name: check ansible_virtualization_type
debug: msg="ansible_virtualization_type = {{ ansible_virtualization_type }}"
when: cwa_debug

- name: Include variables for Debian
include_vars: "{{ item }}"
with_first_found:
- "debian.yml"
- "main.yml"
when: >
ansible_os_family == 'Debian' and
ansible_distribution == 'Debian'
tags:
- include-debian-vars
- name: Set architecture name
set_fact:
cwa_arch_name: "{{ cwa_arch_names.get(ansible_architecture) }}"

- name: Include variables for Ubuntu
# Include of vars
- name: Include variables for {{ ansible_distribution|lower }}
include_vars: "{{ item }}"
with_first_found:
- "ubuntu.yml"
- "{{ ansible_distribution|lower }}-{{ ansible_distribution_major_version }}.yml"
- "main.yml"
when: >
ansible_os_family == 'Debian' and
ansible_distribution == 'Ubuntu'
ansible_os_family == 'RedHat' or ansible_os_family == 'Debian'
tags:
- include-ubuntu-vars
- include-vars

# Installation tasks
- name: Include tasks for installation on RedHat/CentOS/Amazon Linux distribution
include_tasks: "install-{{ ansible_os_family|lower }}.yml"
when: >
ansible_os_family == 'RedHat' and (
ansible_distribution == 'CentOS' or
ansible_distribution == 'RedHat' or
ansible_distribution == 'Amazon'
)
tags:
- include-redhat-tags

- name: Include tasks for installation on Debian/Ubuntu distribution
- name: Include tasks for installation on {{ ansible_os_family|lower }} distribution
include_tasks: "install-{{ ansible_os_family|lower }}.yml"
when: >
ansible_os_family == 'Debian' and (
ansible_distribution == 'Debian' or
ansible_distribution == 'Ubuntu'
)
ansible_os_family == 'RedHat' or ansible_os_family == 'Debian'
tags:
- include-debian-tags
- include-install-task

# Configuration tasks
- name: Configure {{ cwa_package }}
- name: Configure {{ cwa_package }} for {{ ansible_distribution|lower }}
include_tasks: "configure.yml"
tags:
- configure
File renamed without changes.
3 changes: 3 additions & 0 deletions vars/amazon-2.yml
@@ -0,0 +1,3 @@
---
cwa_package_url: https://s3.amazonaws.com/amazoncloudwatch-agent/amazon_linux/{{ cwa_arch_name }}/latest/amazon-cloudwatch-agent.rpm
cwa_package_signature: https://s3.amazonaws.com/amazoncloudwatch-agent/amazon_linux/{{ cwa_arch_name }}/latest/amazon-cloudwatch-agent.rpm.sig
File renamed without changes.
3 changes: 3 additions & 0 deletions vars/centos-7.yml
@@ -0,0 +1,3 @@
---
cwa_package_url: https://s3.amazonaws.com/amazoncloudwatch-agent/centos/{{ cwa_arch_name }}/latest/amazon-cloudwatch-agent.rpm
cwa_package_signature: https://s3.amazonaws.com/amazoncloudwatch-agent/centos/{{ cwa_arch_name }}/latest/amazon-cloudwatch-agent.rpm.sig
3 changes: 3 additions & 0 deletions vars/centos-8.yml
@@ -0,0 +1,3 @@
---
cwa_package_url: https://s3.amazonaws.com/amazoncloudwatch-agent/centos/{{ cwa_arch_name }}/latest/amazon-cloudwatch-agent.rpm
cwa_package_signature: https://s3.amazonaws.com/amazoncloudwatch-agent/centos/{{ cwa_arch_name }}/latest/amazon-cloudwatch-agent.rpm.sig
File renamed without changes.
6 changes: 6 additions & 0 deletions vars/debian-11.yml
@@ -0,0 +1,6 @@
---
cwa_package_url: https://s3.amazonaws.com/amazoncloudwatch-agent/debian/{{ cwa_arch_name }}/latest/amazon-cloudwatch-agent.deb
cwa_package_signature: https://s3.amazonaws.com/amazoncloudwatch-agent/debian/{{ cwa_arch_name }}/latest/amazon-cloudwatch-agent.deb.sig

cwa_gpg_dependencies_packages:
- gpg
6 changes: 6 additions & 0 deletions vars/debian-12.yml
@@ -0,0 +1,6 @@
---
cwa_package_url: https://s3.amazonaws.com/amazoncloudwatch-agent/debian/{{ cwa_arch_name }}/latest/amazon-cloudwatch-agent.deb
cwa_package_signature: https://s3.amazonaws.com/amazoncloudwatch-agent/debian/{{ cwa_arch_name }}/latest/amazon-cloudwatch-agent.deb.sig

cwa_gpg_dependencies_packages:
- gpg
6 changes: 6 additions & 0 deletions vars/debian-8.yml
@@ -0,0 +1,6 @@
---
cwa_package_url: https://s3.amazonaws.com/amazoncloudwatch-agent/debian/{{ cwa_arch_name }}/latest/amazon-cloudwatch-agent.deb
cwa_package_signature: https://s3.amazonaws.com/amazoncloudwatch-agent/debian/{{ cwa_arch_name }}/latest/amazon-cloudwatch-agent.deb.sig

cwa_gpg_dependencies_packages:
- gnupg
6 changes: 6 additions & 0 deletions vars/debian-9.yml
@@ -0,0 +1,6 @@
---
cwa_package_url: https://s3.amazonaws.com/amazoncloudwatch-agent/debian/{{ cwa_arch_name }}/latest/amazon-cloudwatch-agent.deb
cwa_package_signature: https://s3.amazonaws.com/amazoncloudwatch-agent/debian/{{ cwa_arch_name }}/latest/amazon-cloudwatch-agent.deb.sig

cwa_gpg_dependencies_packages:
- gpg
5 changes: 5 additions & 0 deletions vars/main.yml
Expand Up @@ -29,3 +29,8 @@ cwa_use_conf_json_template: "{{ false|bool if cwa_conf_json_file_content is defi

# defined in defaults/main.yaml
cwa_need_credentials: "{{ true|bool if cwa_agent_mode == 'onPremise' else cwa_use_credentials }}"

cwa_arch_names: {
"x86_64": "amd64",
"aarch64": "arm64"
}
File renamed without changes.

0 comments on commit cc03b2e

Please sign in to comment.