From edcba065a8d576a43f7d895973ed6cf9c2950cdf Mon Sep 17 00:00:00 2001 From: Chithra K <63741367+Chithrak07@users.noreply.github.com> Date: Wed, 2 Dec 2020 05:10:01 +0530 Subject: [PATCH] Add automated tests (#1) * Add automated tests * Add tests * Fix molecule tests * Add status badge * Fix molecule tests * Fix molecule tests * Fix molecule tests * Don't duplicate what the role is supposed to do * Add functional test: Make sure logging goes to its own file Co-authored-by: Dale Anderson --- .github/workflows/molecule.yml | 46 +++++++++++++++++++++++++++ README.md | 2 ++ molecule/default/INSTALL.rst | 22 +++++++++++++ molecule/default/converge.yml | 58 ++++++++++++++++++++++++++++++++++ molecule/default/molecule.yml | 20 ++++++++++++ molecule/default/verify.yml | 25 +++++++++++++++ tasks/main.yml | 3 +- 7 files changed, 175 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/molecule.yml create mode 100644 molecule/default/INSTALL.rst create mode 100644 molecule/default/converge.yml create mode 100644 molecule/default/molecule.yml create mode 100644 molecule/default/verify.yml diff --git a/.github/workflows/molecule.yml b/.github/workflows/molecule.yml new file mode 100644 index 0000000..642c88b --- /dev/null +++ b/.github/workflows/molecule.yml @@ -0,0 +1,46 @@ +--- +on: + # Trigger the workflow on push or pull request, + # but only for the main branch + push: + branches: + - master + pull_request: + branches: + - master +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v2 + with: + path: "${{ github.repository }}" + - name: molecule + uses: robertdebock/molecule-action@2.6.3 + with: + command: lint + test: + needs: + - lint + runs-on: ubuntu-latest + strategy: + matrix: + image: + - geerlingguy/docker-ubuntu2004-ansible:latest + - geerlingguy/docker-ubuntu1804-ansible:latest + - geerlingguy/docker-ubuntu1604-ansible:latest + - geerlingguy/docker-centos8-ansible:latest + - geerlingguy/docker-centos7-ansible:latest + steps: + - name: checkout + uses: actions/checkout@v2 + with: + path: "${{ github.repository }}" + - name: molecule + uses: robertdebock/molecule-action@2.6.3 + with: + image: "${{ matrix.image }}" + options: parallel + env: + MOLECULE_DOCKER_IMAGE: "${{ matrix.image }}" diff --git a/README.md b/README.md index 5ceb26a..57d0782 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Ansible Role: acromedia.drupal-syslog +![.github/workflows/molecule.yml](https://github.com/AcroMedia/ansible-role-drupal-syslog/workflows/.github/workflows/molecule.yml/badge.svg) + When using the Drupal Syslog module, redirect logging to a specific file, instead of having drupal write to the system's generic /var/log/(messages|syslog), which can become swamped very quickly by Drupal's watchdog activity. diff --git a/molecule/default/INSTALL.rst b/molecule/default/INSTALL.rst new file mode 100644 index 0000000..6a44bde --- /dev/null +++ b/molecule/default/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 + + $ pip install 'molecule[docker]' diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml new file mode 100644 index 0000000..4a1f82c --- /dev/null +++ b/molecule/default/converge.yml @@ -0,0 +1,58 @@ +--- +- name: Converge + hosts: all + become: true + + vars: + drupal_log_path: /var/log/vhosts/account/project/drupal.log + drupal_syslog_read_users: + - johndoe + + pre_tasks: + + - name: Update apt cache. + apt: update_cache=true cache_valid_time=600 + changed_when: false + when: ansible_os_family == 'Debian' + + - name: Creates directory + file: + path: /var/log/vhosts/account/project + state: directory + + - name: Creates directory + file: + path: /etc/rsyslog.d + state: directory + + - stat: path=/var/log/vhosts/account/project/drupal.log + register: dlog + + - name: Add system users for Debian + user: + name: "johndoe" + state: "present" + groups: "sudo" + append: yes + when: ansible_os_family == 'Debian' + + - name: Add system users for RedHat + user: + name: "johndoe" + state: "present" + groups: "wheel" + append: yes + when: ansible_os_family == 'RedHat' + + - name: Install rsyslog + package: + name: rsyslog + state: latest + + - name: Install acl + package: + name: acl + state: latest + + roles: + - role: ansible-role-drupal-syslog diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml new file mode 100644 index 0000000..7d4ff10 --- /dev/null +++ b/molecule/default/molecule.yml @@ -0,0 +1,20 @@ +--- +dependency: + name: galaxy +driver: + name: docker +platforms: + - name: instance + image: ${MOLECULE_DOCKER_IMAGE:-'geerlingguy/docker-ubuntu1804-ansible:latest'} + command: ${MOLECULE_DOCKER_COMMAND:-""} + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + privileged: true + pre_build_image: true +provisioner: + name: ansible + playbooks: + converge: ${MOLECULE_PLAYBOOK:-converge.yml} + config_options: + defaults: + verbosity: ${MOLECULE_VERBOSITY:-0} diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml new file mode 100644 index 0000000..5c353c3 --- /dev/null +++ b/molecule/default/verify.yml @@ -0,0 +1,25 @@ +--- +- name: Verify role + hosts: all + become: yes + + vars: + drupal_log_path: /var/log/vhosts/account/project/drupal.log + drupal_syslog_read_users: + - johndoe + + tasks: + - name: Obtain the ACL for drupal log + acl: + path: "{{ drupal_log_path }}" + register: acl_info + + - debug: var=acl_info + + - name: Write a line to syslog local0 + command: > + logger --priority local0.info "foo is a bar" + + - name: Make sure our line got logged + command: + grep -w "foo is a bar" /var/log/vhosts/account/project/drupal.log diff --git a/tasks/main.yml b/tasks/main.yml index 9bffcf9..0fcb90c 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -33,7 +33,6 @@ owner: root group: root notify: ards restart rsyslog - # Permissions shouldn't ever need to be re-added to this, since the log file gets copytruncate'd - name: Give additional ACL permissions on {{ drupal_log_path }} to users specified by drupal_syslog_read_users acl: @@ -43,6 +42,8 @@ permissions: r state: present with_items: "{{ drupal_syslog_read_users }}" + + # when: drupal_syslog_read_users|length > 0 # Permissions shouldn't ever need to be re-added to this, since the log file gets copytruncate'd