From 7b74665f912d11ad7e934ac4d9d376cbf909d87e Mon Sep 17 00:00:00 2001 From: Glauber Batista Date: Wed, 29 Nov 2023 11:22:20 -0300 Subject: [PATCH] chore: add verify playbook and more images to test --- molecule/default/molecule.yml | 29 ++++++++++++++++----------- molecule/default/verify.yml | 37 +++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 11 deletions(-) create mode 100644 molecule/default/verify.yml diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index 7d1e022..1187265 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -7,25 +7,32 @@ lint: | set -e yamllint . platforms: - # - name: bionic - # image: solita/ubuntu-systemd:18.04 - # privileged: true - # command: /sbin/init + - name: bionic + image: geerlingguy/docker-ubuntu1804-ansible:latest + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + cgroupns_mode: host + privileged: true + pre_build_image: true - name: focal image: geerlingguy/docker-ubuntu2004-ansible:latest - command: ${MOLECULE_DOCKER_COMMAND:-""} volumes: - /sys/fs/cgroup:/sys/fs/cgroup:rw cgroupns_mode: host privileged: true pre_build_image: true - # command: ${MOLECULE_DOCKER_COMMAND:-""} - # volumes: - # - /sys/fs/cgroup:/sys/fs/cgroup:rw - # cgroupns_mode: host - # privileged: true - # pre_build_image: true + - name: jammy + image: geerlingguy/docker-ubuntu2204-ansible:latest + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + cgroupns_mode: host + privileged: true + pre_build_image: true provisioner: name: ansible lint: name: ansible-lint +scenario: + name: default +verifier: + name: ansible diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml new file mode 100644 index 0000000..58d6c6c --- /dev/null +++ b/molecule/default/verify.yml @@ -0,0 +1,37 @@ +--- +- hosts: all + roles: + - role: ansible-role-cloudwatch-logs + cw_server_type: onPremise + aws_region: us-east-1 + cw_logs_files: + - log_group_name: /var/log/syslog + log_stream_name: '{hostname}-{instance_id}' + timestamp_format: '%b %d %H:%M:%S' + file_path: /var/log/syslog + encoding: utf-8 + - log_group_name: /var/log/auth.log + log_stream_name: '{hostname}-{instance_id}' + timestamp_format: '%b %d %H:%M:%S' + file_path: /var/log/auth.log + encoding: utf-8 + post_tasks: + - name: Ensure log configurations in place + shell: "grep -q {{ item }} /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent.json" + changed_when: false + with_items: "{{ cw_logs_files|map(attribute='log_group_name')|list }}" + + - name: Check agent status + shell: "/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a status" + changed_when: false + register: agent_status + + - name: Fail if agent not running + fail: + msg: "The CloudWatch agent is not running" + when: "'running' not in agent_status.stdout" + + - name: Fail if agent not configured + fail: + msg: "The CloudWatch agent is not running" + when: "'\"configured\"' not in agent_status.stdout"