Skip to content

Commit

Permalink
Merge pull request #28 from christiangda/develop
Browse files Browse the repository at this point in the history
* resolve issue #24
* Improved and updated molecule
* updated travis-ci to use python 3.8
  • Loading branch information
christiangda committed May 30, 2020
2 parents a53eaa0 + 2e970c1 commit 0d86fd6
Show file tree
Hide file tree
Showing 20 changed files with 161 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -3,7 +3,7 @@ language: python

python:
- "2.7"
- "3.7"
- "3.8"
services: docker

branches:
Expand Down
4 changes: 4 additions & 0 deletions .vscode/settings.json
@@ -0,0 +1,4 @@
{
"python.pythonPath": "/home/christian/git/github.com/christiangda/ansible-roles/venv/bin/python",
"restructuredtext.confPath": ""
}
6 changes: 4 additions & 2 deletions README.md
Expand Up @@ -48,7 +48,6 @@ This role work on RedHat, CentOS, Amazon Linux, Debian and Ubuntu distributions
* 14.04 (*)
* 16.04 (*)
* 18.04
* 19.04
* Debian
* jessie (8) (*)
* stretch (9)
Expand All @@ -65,7 +64,7 @@ To see the compatibility matrix of Python vs. Ansible versions see [Travis-CI bu
| :------------------------- | :---------------------- |
| cwa_conf_json_file_content | "" --> Empty |
| cwa_agent_mode | "ec2" |
| cwa_aws_region | "eu-west-1" |
| cwa_aws_region | "" |
| cwa_use_credentials | false |
| cwa_profile | "AmazonCloudWatchAgent" |
| cwa_agent_profile_path | /root |
Expand Down Expand Up @@ -348,6 +347,7 @@ If you want to contribute to this project what you want to do is
* Create a Pull Request to official project `develop` branch

References

* [Fork a repo](https://help.github.com/en/github/getting-started-with-github/fork-a-repo)
* [Creating a pull request from a fork](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request-from-a-fork)

Expand All @@ -364,6 +364,8 @@ source venv/bin/activate
pip install pip --upgrade
pip install ansible
pip install molecule
pip install 'molecule[docker]'
pip install 'molecule[lint]'
pip install molecule-vagrant
pip install python-vagrant
pip install selinux
Expand Down
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
2.0.5
2.0.6
5 changes: 5 additions & 0 deletions VERSION.md
@@ -1,5 +1,10 @@
# VERSION Details

## 2.0.6

* Improved the use of the `cwa_aws_region` Variable, resolve issue #24[Leaving the Region Value out of amazon-cloudwatch-agent.json #24](https://github.com/christiangda/ansible-role-amazon-cloudwatch-agent/issues/24)
* Now the variable `cwa_aws_region` is empty by default, so you need to take care to define it when are you are in OnPremise

## 2.0.5

* Fix collectd search failed #23 [ubuntu: fix gpg signature download](https://github.com/christiangda/ansible-role-amazon-cloudwatch-agent/pull/23)
Expand Down
7 changes: 4 additions & 3 deletions defaults/main.yml
Expand Up @@ -39,11 +39,12 @@ cwa_agent_mode: "ec2"

# description: AWS Region where you want the AWS CloudWatch Logs
# possible values:
# - https://docs.aws.amazon.com/general/latest/gr/rande.html
# default value: "eu-west-1"
# - https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-Configuration-File-Details.html
# default value: ""
# notes:
# * This is the region where the agent have access to push logs/metrics, only necessary when use **cwa_agent_mode:** "onPremise"
cwa_aws_region: "eu-west-1"
# * If you are inside EC2 and left the region variable blank, it will getting from metadata
cwa_aws_region: ""

# description: Define if you want to use AWS CLI Credentials or the AWS EC2 Instance Role
# possible values:
Expand Down
22 changes: 22 additions & 0 deletions molecule/centos-8/INSTALL.rst
@@ -0,0 +1,22 @@
*******
Docker driver installation guide
*******

Requirements
============

* Docker Engine

Install
=======

Please refer to the `Virtual environment`_ documentation for installation best
practices. If not using a virtual environment, please consider passing the
widely recommended `'--user' flag`_ when invoking ``pip``.

.. _Virtual environment: https://virtualenv.pypa.io/en/latest/
.. _'--user' flag: https://packaging.python.org/tutorials/installing-packages/#installing-to-the-user-site

.. code-block:: bash
$ python3 -m pip install 'molecule[docker]'
28 changes: 28 additions & 0 deletions molecule/centos-8/converge.yml
@@ -0,0 +1,28 @@
---
- name: Converge
hosts: all

roles:
- role: christiangda.epel_repo
when: >
ansible_os_family == 'RedHat' and (
ansible_distribution == 'CentOS' or
ansible_distribution == 'RedHat' or
ansible_distribution == 'Amazon'
)
- role: christiangda.awscli_configure
vars:
awscliconf_path: '/root'
awscliconf_files:
credentials:
- AmazonCloudWatchAgent:
aws_access_key_id: 'AKIAIOSFODNN7EXAMPLE'
aws_secret_access_key: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY'
config:
- profile AmazonCloudWatchAgent:
region: eu-west-1
- role: christiangda.amazon_cloudwatch_agent
vars:
cwa_agent_mode: "onPremise"
cwa_profile: "AmazonCloudWatchAgent"
cwa_aws_region: "eu-west-1"
19 changes: 19 additions & 0 deletions molecule/centos-8/molecule.yml
@@ -0,0 +1,19 @@
---
dependency:
name: galaxy

driver:
name: docker
platforms:
- name: centos-8
image: centos:8

provisioner:
name: ansible
#log: true

verifier:
name: ansible

scenario:
name: centos-8
3 changes: 3 additions & 0 deletions molecule/centos-8/requirements.yml
@@ -0,0 +1,3 @@
---
- src: christiangda.epel_repo
- src: christiangda.awscli_configure
14 changes: 14 additions & 0 deletions molecule/centos-8/tests/test_default.py
@@ -0,0 +1,14 @@
import os

import testinfra.utils.ansible_runner

testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')


def test_hosts_file(host):
f = host.file('/etc/hosts')

assert f.exists
assert f.user == 'root'
assert f.group == 'root'
15 changes: 0 additions & 15 deletions molecule/default/Dockerfile.j2

This file was deleted.

14 changes: 10 additions & 4 deletions molecule/default/INSTALL.rst
Expand Up @@ -5,12 +5,18 @@ Docker driver installation guide
Requirements
============

* General molecule dependencies (see https://molecule.readthedocs.io/en/latest/installation.html)
* Docker Engine
* docker-py
* docker

Install
=======

$ sudo pip install docker-py
Please refer to the `Virtual environment`_ documentation for installation best
practices. If not using a virtual environment, please consider passing the
widely recommended `'--user' flag`_ when invoking ``pip``.

.. _Virtual environment: https://virtualenv.pypa.io/en/latest/
.. _'--user' flag: https://packaging.python.org/tutorials/installing-packages/#installing-to-the-user-site

.. code-block:: bash
$ python3 -m pip install 'molecule[docker]'
Expand Up @@ -8,6 +8,14 @@
when: ansible_os_family == 'Debian'
changed_when: false

- name: Install gnupg
apt:
name: gnupg
state: latest
when: ansible_os_family == 'Debian'
changed_when: false


roles:
- role: christiangda.epel_repo
when: >
Expand All @@ -31,3 +39,4 @@
vars:
cwa_agent_mode: "onPremise"
cwa_profile: "AmazonCloudWatchAgent"
cwa_aws_region: "eu-west-1"
59 changes: 30 additions & 29 deletions molecule/default/molecule.yml
Expand Up @@ -2,29 +2,6 @@
dependency:
name: galaxy

# lint:
# name: yamllint
# enabled: true
# options:
# config-data:
# ignore: venv
# provisioner:
# name: ansible
# lint:
# name: ansible-lint
# options:
# x: ["403"]
# verifier:
# name: testinfra
# lint:
# name: flake8

lint: |
set -e
yamllint .
ansible-lint
flake8
driver:
name: docker
platforms:
Expand All @@ -43,20 +20,44 @@ platforms:
- name: amazonlinux-2
image: amazonlinux:2

- name: ubuntu-19.04
image: ubuntu:19.04

- name: ubuntu-18.04
image: ubuntu:18.04

- name: debian-sid
image: debian:sid

- name: debian-buster
image: debian:buster

- name: debian-stretch
image: debian:stretch

# lint:
# name: yamllint
# enabled: true
# options:
# config-data:
# ignore: venv
# provisioner:
# name: ansible
# lint:
# name: ansible-lint
# options:
# x: ["403"]
# verifier:
# name: testinfra
# lint:
# name: flake8

# lint: |
# set -e
# yamllint .
# ansible-lint
# flake8

provisioner:
name: ansible
#log: true

verifier:
name: ansible

scenario:
name: default
7 changes: 3 additions & 4 deletions molecule/vagrant/INSTALL.rst
@@ -1,12 +1,11 @@
*******
Vagrant driver installation guide
Docker driver installation guide
*******

Requirements
============

* Vagrant
* Virtualbox, Parallels, VMware Fusion, VMware Workstation or VMware Desktop
* Docker Engine

Install
=======
Expand All @@ -20,4 +19,4 @@ widely recommended `'--user' flag`_ when invoking ``pip``.

.. code-block:: bash
$ pip install 'molecule[vagrant]'
$ python3 -m pip install 'molecule[docker]'
Expand Up @@ -35,3 +35,4 @@
vars:
cwa_agent_mode: "onPremise"
cwa_profile: "AmazonCloudWatchAgent"
cwa_aws_region: "eu-west-1"
5 changes: 0 additions & 5 deletions molecule/vagrant/molecule.yml
Expand Up @@ -45,11 +45,6 @@ platforms:
memory: 512
cpus: 1

# - name: ubuntu-19.04
# box: ubuntu/disco64
# memory: 512
# cpus: 1

- name: ubuntu-18.04
box: ubuntu/bionic64
memory: 512
Expand Down
1 change: 1 addition & 0 deletions tasks/install-redhat.yml
Expand Up @@ -4,6 +4,7 @@
state: present
key: "{{ cwa_package_gpg }}"
tags:
- molecule-idempotence-notest # Added because I got the folowing error: [centos-8] => christiangda.amazon_cloudwatch_agent : Add amazon-cloudwatch-agent key
- add-key
- download
- install
Expand Down
2 changes: 2 additions & 0 deletions templates/agent/amazon-cloudwatch-agent.json.j2
@@ -1,7 +1,9 @@
{
"agent": {
"metrics_collection_interval": 60,
{% if cwa_aws_region is not none and cwa_aws_region|length > 0 -%}
"region": "{{ cwa_aws_region }}",
{% endif -%}
"logfile": "{{ cwa_agent_log_file }}",
"debug": false
},
Expand Down

0 comments on commit 0d86fd6

Please sign in to comment.