Skip to content

Commit

Permalink
Fixed #14, and others improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
christiangda committed Jan 4, 2020
2 parents 818dc57 + d8b8d3b commit 8f5cefa
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 88 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -348,6 +348,7 @@ pip install pip --upgrade
pip install ansible
pip install molecule
pip install molecule[vagrant]
pip install python-vagrant
pip install selinux
pip install docker
pip install pytest
Expand Down
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
2.0.2
2.0.3
5 changes: 5 additions & 0 deletions VERSION.md
@@ -1,5 +1,10 @@
# VERSION Details

## 2.0.3

* Fixed variable problem reporte in issue #14 [cwa_use_credentials: false is not working for role based installation](https://github.com/christiangda/ansible-role-amazon-cloudwatch-agent/issues/14)
* Debian Family now detect automatically the installation of collectd dependency

## 2.0.2

* Improved to support ansible playbooks with option `--check` reporte in issue #8 [playbook fails on --check](https://github.com/christiangda/ansible-role-amazon-cloudwatch-agent/issues/8)
Expand Down
2 changes: 1 addition & 1 deletion molecule/default/Dockerfile.j2
Expand Up @@ -6,7 +6,7 @@ FROM {{ item.registry.url }}/{{ item.image }}
FROM {{ item.image }}
{% endif %}

RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \
RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python python-apt sudo bash ca-certificates && apt-get clean; \
elif [ $(command -v dnf) ] && [ $(rpm --query 'centos-release-8*' 'redhat-release-8*' | grep -v 'is not installed') ]; then dnf install -y python3 python3-devel python3-dnf python3-pip && dnf clean all && ln -s /usr/bin/python3 /usr/bin/python; \
elif [ $(command -v dnf) ] && ![ $(rpm --query 'centos-release-8*' 'redhat-release-8*' | grep -v 'is not installed') ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python2-dnf bash && dnf clean all; \
elif [ $(command -v yum) ] && ![ $(rpm --query 'centos-release-8*' 'redhat-release-8*' | grep -v 'is not installed') ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \
Expand Down
8 changes: 4 additions & 4 deletions molecule/vagrant/molecule.yml
Expand Up @@ -44,10 +44,10 @@ platforms:
memory: 512
cpus: 1

- name: debian-sid
box: debian/testing64
memory: 512
cpus: 1
# - name: debian-sid
# box: debian/testing64
# memory: 512
# cpus: 1

- name: debian-10
box: debian/buster64
Expand Down
64 changes: 0 additions & 64 deletions molecule/vagrant/playbook.yml
Expand Up @@ -47,67 +47,3 @@
vars:
cwa_agent_mode: "onPremise"
cwa_profile: "AmazonCloudWatchAgent"
# - role: christiangda.amazon_cloudwatch_agent
# vars:
# cwa_agent_mode: onPremise
# cwa_aws_region: "eu-west-1"
# cwa_profile: "AmazonCloudWatchAgent"
# cwa_conf_json_file_content:
# agent:
# metrics_collection_interval: 60
# region: es-west-1
# logfile: "/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log"
# debug: false
# metrics:
# metrics_collected:
# collectd: {}
# cpu:
# resources:
# - "*"
# measurement:
# - name: cpu_usage_idle
# rename: CPU_USAGE_IDLE
# unit: Percent
# - name: cpu_usage_nice
# unit: Percent
# - cpu_usage_guest
# totalcpu: false
# metrics_collection_interval: 10
# append_dimensions:
# test: test1
# date: "2017-10-01"
# netstat:
# measurement:
# - tcp_established
# - tcp_syn_sent
# - tcp_close
# metrics_collection_interval: 60
# processes:
# measurement:
# - running
# - sleeping
# - dead
# append_dimensions:
# ImageId: "${!aws:ImageId}"
# InstanceId: "${!aws:InstanceId}"
# InstanceType: "${!aws:InstanceType}"
# AutoScalingGroupName: "${!aws:AutoScalingGroupName}"
# aggregation_dimensions:
# - - AutoScalingGroupName
# - - InstanceId
# - InstanceType
# - []
# logs:
# logs_collected:
# files:
# collect_list:
# - file_path: "/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log"
# log_group_name: amazon-cloudwatch-agent.log
# log_stream_name: amazon-cloudwatch-agent.log
# timezone: UTC
# - file_path: "/opt/aws/amazon-cloudwatch-agent/logs/test.log"
# log_group_name: test.log
# log_stream_name: test.log
# timezone: Local
# log_stream_name: my_log_stream_name
# force_flush_interval: 15
21 changes: 6 additions & 15 deletions molecule/vagrant/prepare.yml
Expand Up @@ -16,20 +16,11 @@
ansible_distribution == 'RedHat' and
ansible_distribution_major_version == '7'
- name: Install python for Ansible
raw: |
if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \
elif [ $(command -v dnf) ] && [ $(rpm --query 'centos-release-8*' 'redhat-release-8*' | grep -v 'is not installed') ]; then dnf install -y python3 python3-devel python3-dnf python3-pip && dnf clean all && ln -s /usr/bin/python3 /usr/bin/python; \
elif [ $(command -v dnf) ] && ![ $(rpm --query 'centos-release-8*' 'redhat-release-8*' | grep -v 'is not installed') ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python2-dnf bash && dnf clean all; \
elif [ $(command -v yum) ] && ![ $(rpm --query 'centos-release-8*' 'redhat-release-8*' | grep -v 'is not installed') ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \
elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml && zypper clean -a; \
elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \
elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates && xbps-remove -O; fi
become: true
changed_when: false
- name: Install RedHat 8 yajl package from mirror.centos.org to avoid Subscription Manager dependencies
dnf:
name: 'http://mirror.centos.org/centos/8/AppStream/x86_64/os/Packages/yajl-2.1.0-10.el8.x86_64.rpm'
state: present
when: >
ansible_os_family == 'RedHat' and (
ansible_distribution == 'CentOS' or
ansible_distribution == 'RedHat'
) and
ansible_os_family == 'RedHat' and
ansible_distribution == 'RedHat' and
ansible_distribution_major_version == '8'
3 changes: 3 additions & 0 deletions molecule/vagrant/requirements.yml
@@ -0,0 +1,3 @@
---
- src: christiangda.epel_repo
- src: christiangda.awscli_configure
2 changes: 1 addition & 1 deletion tasks/configure.yml
Expand Up @@ -34,7 +34,7 @@
when: profile_credentials_file.stat.exists is defined and profile_credentials_file.stat.exists and presence.changed

ignore_errors: "{{ ansible_check_mode }}"
when: cwa_use_credentials or cwa_agent_mode == 'onPremise'
when: cwa_need_credentials

- name: Deploy {{ cwa_package }} common configuration file
template:
Expand Down
3 changes: 2 additions & 1 deletion tasks/install-debian.yml
Expand Up @@ -48,7 +48,7 @@
- verify-signature
- install

- name: Install {{ cwa_package }} dependencies
- name: Install {{ cwa_package }} dependencies on Debian Family
apt:
name: "{{ cwa_dependencies_packages }}"
state: present
Expand All @@ -57,6 +57,7 @@
retries: "{{ cwa_global_downloads_retries }}"
delay: "{{ cwa_global_downloads_delay }}"
until: package_ok is success
when: cwa_conf_json_file_content is search("collectd")
tags:
- install

Expand Down
2 changes: 1 addition & 1 deletion templates/agent/common-config.toml.j2
Expand Up @@ -5,7 +5,7 @@
## Default credential strategy will be used if it is absent here:
## Instance role is used for EC2 case by default.
## AmazonCloudWatchAgent profile is used for onPremise case by default.
{% if cwa_use_credentials %}
{% if cwa_need_credentials %}
[credentials]
shared_credential_profile = "{{ cwa_profile }}"
shared_credential_file= "{{ cwa_agent_profile_credentials_file }}"
Expand Down
2 changes: 2 additions & 0 deletions vars/main.yml
Expand Up @@ -27,3 +27,5 @@ cwa_agent_profile_credentials_file: "{{ cwa_agent_profile_path }}/.aws/credentia
cwa_use_proxy: "{{ true|bool if cwa_http_proxy is defined and cwa_http_proxy|length > 0 else false|bool }}"
cwa_use_conf_json_template: "{{ false|bool if cwa_conf_json_file_content is defined and cwa_conf_json_file_content|length > 0 else true|bool }}"

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

0 comments on commit 8f5cefa

Please sign in to comment.