Skip to content

Commit

Permalink
test: add failing test for default scenario
Browse files Browse the repository at this point in the history
Issues: #2
  • Loading branch information
geoffreyvanwyk committed Jan 9, 2024
1 parent c362da9 commit 6d75ecd
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 26 deletions.
33 changes: 13 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ At the moment, the role only uses Apache web server which it installs itself.

The role only supports removing the included Apache web configuration as for a Moodle instance installed in a subdirectory; not the removal of a virtual host configuration.

The role only supports PostgreSQL database.

## Role Variables

> A description of the settable variables for this role should go here,
Expand All @@ -32,53 +34,44 @@ The role only supports removing the included Apache web configuration as for a M
> are read from other roles and/or the global scope (ie. hostvars, group vars,
> etc.) should be mentioned here as well.
### Deployment of Source Code
### Delete Source Code

```yaml
moodle_deploy_destination: /var/www/html/moodle
moodle_deploy_destination: ""
```
The path to the Moodle source code.
---
### Set-Up of Database
### Drop Database
```yaml
moodle_cfg_dbtype: pgsql # Which database service is used: pgsql or maridb.
moodle_cfg_dbname: moodle # The name of the database.
moodle_cfg_dbuser: # Username.
moodle_cfg_dbpass: # Password.
moodle_cfg_dbtype: pgsql
moodle_cfg_dbname: ""
```
The database user provided must have permission to drop the database. If no username and password are given, for PostgreSQL, the `postgres` user will be used; for MariaDB, the socket will be used, if possible.
The `postgres` user is used to drop the database.

---

### Web Hosting
### Remove Apache configuration

```yaml
moodle_web_domain: 127.0.0.1 # Domain name of the web service virtual host.
moodle_web_path: moodle # Subdirectory relative to virtual host.
moodle_web_apache_conf: "" # Name of included Apache configuraion file.
```

As with the Ansible role for Moodle, These two variables are used to calculate the `moodle_instance` variable that uniquely identifies the Moodle instance. The `moodle_instance` variable is used to:

* locate the moodledata directory, unless that path is explicitly given;
* locate the included Apache configuration file;
* identify the cronjob that needs to be removed.

If the `moodle_web_path` is not given, it is calculated from the basename `moodle_deploy_destination`.
The name of included Apache configuration file.

---

### Installation & Server-Side configuration

```yaml
moodle_cfg_dataroot: /var/www/moodledata
moodle_cfg_dataroot: ""
```

The path to the moodledata directory. If not given, it is calculated from the `moodle_instance` variable.
The path to the moodledata directory.

## Dependencies

Expand Down
4 changes: 2 additions & 2 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
- name: Converge
hosts: all
tasks:
- name: "Include geoffreyvanwyk.moodle_uninstall"
- name: Uninstall Moodle
ansible.builtin.include_role:
name: "geoffreyvanwyk.moodle_uninstall"
name: geoffreyvanwyk.moodle_uninstall
10 changes: 8 additions & 2 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,16 @@ dependency:
driver:
name: docker
platforms:
- name: instance
image: "geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2004}-ansible:latest"
- name: ansible_role_moodle_uninstall_${MOLECULE_DISTRO:-ubuntu2204}
image: "geoffreyvanwyk/docker-${MOLECULE_DISTRO:-ubuntu2004}-ansible:latest"
pre_build_image: true
published_ports:
- "0.0.0.0:80:80"
provisioner:
name: ansible
inventory:
host_vars:
ansible_role_moodle_uninstall_${MOLECULE_DISTRO:-ubuntu2204}:
ansible_user: ubuntu
verifier:
name: ansible
39 changes: 39 additions & 0 deletions molecule/default/prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
# This file is part of Ansible role geoffreyvanwyk.moodle_uninstall.
#
# Ansible role geoffreyvanwyk.moodle_uninstall is free software: you can
# redistribute it and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# Ansible role geoffreyvanwyk.moodle_uninstall is distributed in the hope that
# it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# Ansible role geoffreyvanwyk.moodle_uninstall. If not, see
# <https://www.gnu.org/licenses/>.

##
# Prepares the server before calling the role that is being tested.
#
# @copyright 2023 Geoffrey Bernardo van Wyk (https://geoffreyvanwyk.dev)
##

- name: Prepare
hosts: all

tasks:
- name: Update APT package cache
# Sometimes the package list on the server does not contain all the
# available packages. A fresh list has to be downloaded from the Ubuntu
# package repositories.
become: true
ansible.builtin.apt:
update_cache: true
cache_valid_time: "{{ 60 * 60 * 24 }}" # seconds => 24 hours

Check warning on line 35 in molecule/default/prepare.yml

View workflow job for this annotation

GitHub Actions / YAML Lint

35:48 [comments] too few spaces before comment

- name: Install Moodle
ansible.builtin.include_role:
name: geoffreyvanwyk.moodle
28 changes: 28 additions & 0 deletions molecule/default/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
# This file is part of Ansible role geoffreyvanwyk.moodle_uninstall.
#
# Ansible role geoffreyvanwyk.moodle_uninstall is free software: you can
# redistribute it and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# Ansible role geoffreyvanwyk.moodle_uninstall is distributed in the hope that
# it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# Ansible role geoffreyvanwyk.moodle_uninstall. If not, see
# <https://www.gnu.org/licenses/>.

##
# Override variables for this Molecule scenario.
#
# @copyright 2023 Geoffrey Bernardo van Wyk (https://geoffreyvanwyk.dev)
##

moodle_deploy_destination: /var/www/html/moodle
moodle_cfg_dataroot: /var/www/moodledata-127.0.0.1-moodle
moodle_cfg_dbtype: pgsql
moodle_cfg_dbname: moodle
moodle_web_apache_conf: moodle_127.0.0.1-moodle.conf
61 changes: 59 additions & 2 deletions molecule/default/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,64 @@
- name: Verify
hosts: all
gather_facts: false

vars_files:
- vars/main.yml

tasks:
- name: Example assertion
- name: Collect list of cron jobs
ansible.builtin.command: crontab -l
changed_when: false
register: moodle_uninstall_cron_jobs

- name: Assert that cron job does not exist
loop: "{{ moodle_uninstall_cron_jobs.stdout_lines }}"
ansible.builtin.assert:
that: "{{ item is not search(moodle_deploy_destination) }}"

- name: Collect list of databases
become: true
become_user: postgres
community.postgresql.postgresql_info:
filter:
- "databases"
register: moodle_uninstall_databases

- name: Assert that database does not exist
ansible.builtin.assert:
that: "{{ moodle_cfg_dbname not in moodle_uninstall_databases.databases.keys() }}"

Check failure on line 53 in molecule/default/verify.yml

View workflow job for this annotation

GitHub Actions / YAML Lint

53:81 [line-length] line too long (90 > 80 characters)

- name: Obtain status enabled Apache configuration
ansible.builtin.stat:
path: /etc/apache2/conf-enabled/{{ moodle_web_apache_conf }}
register: moodle_uninstall_stat_enabled_apache_conf

- name: Assert that enabled Apache configuration does not exist
ansible.builtin.assert:
that: not moodle_uninstall_stat_enabled_apache_conf.stat.exists

- name: Obtain status available Apache configuration
ansible.builtin.stat:
path: /etc/apache2/conf-available/{{ moodle_web_apache_conf }}
register: moodle_uninstall_stat_available_apache_conf

- name: Assert that available Apache configuration does not exist
ansible.builtin.assert:
that: not moodle_uninstall_stat_available_apache_conf.stat.exists
- name: Obtain status of Moodle source code directory
ansible.builtin.stat:
path: "{{ moodle_deploy_destination }}"
register: moodle_uninstall_stat_deploy_destination

- name: Assert that Moodle source code directory does not exist
ansible.builtin.assert:
that: not moodle_uninstall_stat_deploy_destination.stat.exists

- name: Obtain status of moodledata directory
ansible.builtin.stat:
path: "{{ moodle_cfg_dataroot }}"
register: moodle_uninstall_stat_moodledata

- name: Assert that Moodledata directory does not exist
ansible.builtin.assert:
that: true
that: not moodle_uninstall_stat_moodledata.stat.exists
24 changes: 24 additions & 0 deletions requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
# This file is part of Ansible role geoffreyvanwyk.moodle_uninstall.
#
# Ansible role geoffreyvanwyk.moodle_uninstall is free software: you can
# redistribute it and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# Ansible role geoffreyvanwyk.moodle_uninstall is distributed in the hope that
# it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# Ansible role geoffreyvanwyk.moodle_uninstall. If not, see
# <https://www.gnu.org/licenses/>.

##
# List of roles on which this role depends.
#
# @copyright 2023 Geoffrey Bernardo van Wyk (https://geoffreyvanwyk.dev)
##

- name: geoffreyvanwyk.moodle

0 comments on commit 6d75ecd

Please sign in to comment.