From bcc85113d69a9dcf4b1b7e2abf7dff27c76bf095 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Gonz=C3=A1lez=20Di=20Antonio?= Date: Fri, 3 Jan 2020 14:49:02 +0100 Subject: [PATCH 1/5] Fixed issue #14 Fixed issue #14 thanks to @shuklaabhi --- vars/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars/main.yml b/vars/main.yml index 2f8dbde..576400f 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -28,4 +28,4 @@ cwa_use_proxy: "{{ true|bool if cwa_http_proxy is defined and cwa_http_proxy|len 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_use_credentials: "{{ true|bool if cwa_agent_mode == 'onPremise' }}" +cwa_use_credentials: "{{ true|bool if cwa_agent_mode == 'onPremise' else cwa_use_credentials }}" From 992f434b819b336853dcfba06c4eb60962d20d37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Gonz=C3=A1lez=20Di=20Antonio?= Date: Fri, 3 Jan 2020 14:51:24 +0100 Subject: [PATCH 2/5] Update VERSION --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index e9307ca..50ffc5a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.0.2 +2.0.3 From 3ba857c4b4a0ddcd2e596ec44b5d6addb12f552e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Gonz=C3=A1lez=20Di=20Antonio?= Date: Fri, 3 Jan 2020 14:54:34 +0100 Subject: [PATCH 3/5] [skip travis] Update VERSION.md --- VERSION.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/VERSION.md b/VERSION.md index 802bf55..ed929b9 100644 --- a/VERSION.md +++ b/VERSION.md @@ -1,5 +1,9 @@ # 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) + ## 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) From 906d8d5f7b5612f1b4cc24f905dfb7fb4c7c5546 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Gonz=C3=A1lez=20Di=20Antonio?= Date: Sat, 4 Jan 2020 09:06:56 +0100 Subject: [PATCH 4/5] Fixed variable problem reporte in issue #14 --- tasks/configure.yml | 2 +- templates/agent/common-config.toml.j2 | 2 +- vars/main.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tasks/configure.yml b/tasks/configure.yml index d466b88..661ed45 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -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 + when: cwa_need_credentials - name: Deploy {{ cwa_package }} common configuration file template: diff --git a/templates/agent/common-config.toml.j2 b/templates/agent/common-config.toml.j2 index 6acdb6f..f05d904 100644 --- a/templates/agent/common-config.toml.j2 +++ b/templates/agent/common-config.toml.j2 @@ -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 }}" diff --git a/vars/main.yml b/vars/main.yml index 576400f..4525a3e 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -28,4 +28,4 @@ cwa_use_proxy: "{{ true|bool if cwa_http_proxy is defined and cwa_http_proxy|len 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_use_credentials: "{{ true|bool if cwa_agent_mode == 'onPremise' else cwa_use_credentials }}" +cwa_need_credentials: "{{ true|bool if cwa_agent_mode == 'onPremise' else cwa_use_credentials }}" From d8b8d3b6bb0e55c7a1547b529fc0b1291f6b5d0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Gonz=C3=A1lez=20Di=20Antonio?= Date: Sat, 4 Jan 2020 10:42:31 +0100 Subject: [PATCH 5/5] Fixed #14, and others improvements --- README.md | 1 + VERSION.md | 1 + molecule/default/Dockerfile.j2 | 2 +- molecule/vagrant/molecule.yml | 8 ++-- molecule/vagrant/playbook.yml | 64 ------------------------------- molecule/vagrant/prepare.yml | 21 +++------- molecule/vagrant/requirements.yml | 3 ++ tasks/install-debian.yml | 3 +- 8 files changed, 18 insertions(+), 85 deletions(-) create mode 100644 molecule/vagrant/requirements.yml diff --git a/README.md b/README.md index f35e29f..7d3a984 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/VERSION.md b/VERSION.md index ed929b9..759f41b 100644 --- a/VERSION.md +++ b/VERSION.md @@ -3,6 +3,7 @@ ## 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 diff --git a/molecule/default/Dockerfile.j2 b/molecule/default/Dockerfile.j2 index a4f71f1..df82457 100644 --- a/molecule/default/Dockerfile.j2 +++ b/molecule/default/Dockerfile.j2 @@ -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; \ diff --git a/molecule/vagrant/molecule.yml b/molecule/vagrant/molecule.yml index e1398fd..b648ae3 100644 --- a/molecule/vagrant/molecule.yml +++ b/molecule/vagrant/molecule.yml @@ -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 diff --git a/molecule/vagrant/playbook.yml b/molecule/vagrant/playbook.yml index 625efe7..d7b13a8 100644 --- a/molecule/vagrant/playbook.yml +++ b/molecule/vagrant/playbook.yml @@ -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 diff --git a/molecule/vagrant/prepare.yml b/molecule/vagrant/prepare.yml index 4ef8760..7aeec96 100644 --- a/molecule/vagrant/prepare.yml +++ b/molecule/vagrant/prepare.yml @@ -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' diff --git a/molecule/vagrant/requirements.yml b/molecule/vagrant/requirements.yml new file mode 100644 index 0000000..d0b1bf6 --- /dev/null +++ b/molecule/vagrant/requirements.yml @@ -0,0 +1,3 @@ +--- +- src: christiangda.epel_repo +- src: christiangda.awscli_configure diff --git a/tasks/install-debian.yml b/tasks/install-debian.yml index 7d5929e..fdf6b82 100644 --- a/tasks/install-debian.yml +++ b/tasks/install-debian.yml @@ -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 @@ -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