Skip to content

Commit

Permalink
Merge pull request #3 from elan-ev/update-tests
Browse files Browse the repository at this point in the history
Update tests and formatting
  • Loading branch information
tibroc authored Sep 29, 2022
2 parents 4b0c7a1 + bc5104e commit e8749c1
Show file tree
Hide file tree
Showing 15 changed files with 141 additions and 63 deletions.
7 changes: 7 additions & 0 deletions .ansible-lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---

# .ansible-lint
exclude_paths:
- .cache/ # implicit unless exclude_paths is defined in config
- .github/
- venv/
6 changes: 6 additions & 0 deletions .dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ansible
ansible-lint
yamllint
molecule
molecule-docker
molecule-podman
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
---

name: ansible tests
name: molecule

on: # yamllint disable-line rule:truthy
- push
- pull_request

jobs:
lint:
molecule:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: install dependencies
run: >
pip3 install
ansible
ansible-lint
yamllint
molecule
molecule-docker
molecule-podman
run: pip3 install -r .dev_requirements.txt

- name: test playbook
run: molecule test --driver-name docker
env:
PY_COLORS: '1'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
venv/
11 changes: 11 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---

extends: default

rules:
line-length: disable

ignore: |
venv/
.roles/
.cache/
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Ansible: Opencast Repository Role
=================================

![molecule](https://github.com/elan-ev/opencast_repository/actions/workflows/molecule.yml/badge.svg)

This Ansible role enables the package repository for RHEL, CentOS, Debian or Ubuntu.


Expand Down Expand Up @@ -36,3 +38,35 @@ Example of how to configure and use the role:
- role: elan.opencast_repository
opencast_version_major: 9
```
Development
-----------
For development and testing you can use [molecule](https://molecule.readthedocs.io/en/latest/).
With podman as driver you can install it like this – preferably in a virtual environment (if you use docker, substitute `podman` with `docker`):

```bash
pip install -r .dev_requirements.txt
```

Then you can *create* the test instances, apply the ansible config (*converge*) and *destroy* the test instances with these commands:

```bash
molecule create
molecule converge
molecule destroy
```

If you want to inspect a running test instance use `molecule login --host <instance_name>`, where you replace `<instance_name>` with the desired value.

To test the role run `molecule test`.

License
-------

[BSD-3-Clause](LICENSE)

Author Information
------------------

[ELAN e.V](https://elan-ev.de/)
2 changes: 1 addition & 1 deletion handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
- name: update apt cache
- name: Update apt cache
ansible.builtin.apt:
update_cache: true
2 changes: 1 addition & 1 deletion meta/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---

galaxy_info:
author: Lars Kiesow
role_name: opencast_repository
Expand All @@ -15,6 +14,7 @@ galaxy_info:
versions:
- "7"
- "8"
- "9"
- name: Debian
versions:
- all
Expand Down
8 changes: 8 additions & 0 deletions molecule/default/Dockerfile.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM {{ item.image }}

# Install dependencies
{% if "centos" in item.name %}
RUN dnf install --refresh -y sudo systemd bash ca-certificates iproute python3 python3-libselinux
{% else %}
RUN apt-get update && apt-get install -y sudo bash ca-certificates iproute2 init python3 && apt-get clean
{% endif %}
4 changes: 2 additions & 2 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
- name: Converge
hosts: all
vars:
opencast_version_major: 10
opencast_version_major: 12
opencast_repository_enabled_release: true
opencast_repository_enabled_testing: true
tasks:
- name: include opencast_repository
- name: Include opencast_repository
ansible.builtin.include_role:
name: opencast_repository
35 changes: 30 additions & 5 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,40 @@ dependency:
driver:
name: podman
platforms:
- name: opencast-repository-centos-8
image: quay.io/centos/centos:stream8
pre_build_image: true
- name: opencast-repository-centos-7
- name: oc_repository_centos_7
image: docker.io/library/centos:7
pre_build_image: true
- name: opencast-repository-debian
- name: oc_repository_centos_8
image: quay.io/centos/centos:stream8
pre_build_image: false
command: /sbin/init
tmpfs:
- /run
- /tmp
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- name: oc_repository_centos_9
image: quay.io/centos/centos:stream9
pre_build_image: false
command: /sbin/init
tmpfs:
- /run
- /tmp
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- name: oc_repository_debian
image: docker.io/library/python:bullseye
pre_build_image: true
- name: oc_repository_ubuntu
image: docker.io/ubuntu:latest
pre_build_image: false
privileged: true
command: /sbin/init
tmpfs:
- /run
- /tmp
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
lint: |
set -e
yamllint .
Expand Down
9 changes: 3 additions & 6 deletions molecule/default/verify.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
---
# This is an example playbook to execute Ansible tests.

- name: Verify
hosts: all
gather_facts: true
vars:
opencast_version_major: 10
opencast_version_major: 12
tasks:
- name: test if opencast is available
- name: Test if opencast is available
ansible.builtin.package:
# yamllint disable-line rule:line-length
name: "{{ 'opencast-' + opencast_version_major|string + '-common' if ansible_os_family == 'Debian' else 'opencast' }}"
name: "{{ 'opencast-' + opencast_version_major | string + '-common' if ansible_os_family == 'Debian' else 'opencast' }}"
state: present
24 changes: 11 additions & 13 deletions tasks/debian.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
---

- name: install dependencies
- name: Install dependencies
ansible.builtin.apt:
name:
- ca-certificates
- gnupg2
state: present
cache_valid_time: 3600

- name: install the opencast package repository key
- name: Install the opencast package repository key
ansible.builtin.apt_key:
url: https://pkg.opencast.org/gpgkeys/opencast-deb.key
state: present

- name: remove orphan opencast package repository definition
- name: Remove orphan opencast package repository definition
notify: Update apt cache
ansible.builtin.apt_repository:
repo: >-
deb https://pkg.opencast.org/debian
{{ opencast_version_major }}.x
stable testing
filename: opencast
state: absent
notify: update apt cache

- name: install the opencast package repository
- name: Install the opencast package repository
notify: Update apt cache
ansible.builtin.apt_repository:
repo: >-
deb https://pkg.opencast.org/debian
{{ opencast_version_major }}.x
stable
deb https://pkg.opencast.org/debian
{{ opencast_version_major }}.x
stable
filename: opencast
# yamllint disable-line rule:line-length
state: "{{ 'present' if opencast_repository_enabled_release | bool else 'absent' }}"
notify: update apt cache

- name: install the opencast testing package repository
- name: Install the opencast testing package repository
notify: Update apt cache
ansible.builtin.apt_repository:
repo: >-
deb https://pkg.opencast.org/debian
Expand All @@ -43,4 +42,3 @@
filename: opencast
# yamllint disable-line rule:line-length
state: "{{ 'present' if opencast_repository_enabled_testing | bool else 'absent' }}"
notify: update apt cache
13 changes: 6 additions & 7 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
---

- name: check that the architecture is supported
- name: Check that the architecture is supported
ansible.builtin.assert:
that: ansible_architecture == 'x86_64'
that: ansible_architecture == "x86_64"

- name: install on debian/ubuntu
- name: Install on debian/ubuntu
ansible.builtin.include_tasks: debian.yml
when: ansible_os_family == 'Debian'
when: ansible_os_family == "Debian"

- name: install on centos
- name: Install on centos
ansible.builtin.include_tasks: rhel.yml
when: ansible_os_family == 'RedHat'
when: ansible_os_family == "RedHat"
33 changes: 15 additions & 18 deletions tasks/rhel.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,34 @@
---

# yamllint disable rule:line-length
- name: install opencast repository
- name: Install opencast repository
ansible.builtin.yum_repository:
file: opencast
name: opencast-{{ item }}
description: Opencast RHEL $releasever Repository - {{ item }}
baseurl: https://pkg.opencast.org/rpms/release/el/$releasever/oc-{{ repository_version }}/{{ item }}
enabled: '{{ opencast_repository_enabled_release }}'
name: "opencast-{{ item }}"
description: "Opencast RHEL $releasever Repository - {{ item }}"
baseurl: "https://pkg.opencast.org/rpms/release/el/$releasever/oc-{{ repository_version }}/{{ item }}"
enabled: "{{ opencast_repository_enabled_release }}"
gpgcheck: true
gpgkey: https://pkg.opencast.org/gpgkeys/opencast-{{ repository_version }}-rpm.key
gpgkey: "https://pkg.opencast.org/gpgkeys/opencast-{{ repository_version }}-rpm.key"
vars:
repository_version: '{{ "%02d" % (opencast_version_major|int) }}'
repository_version: '{{ "%02d" % (opencast_version_major | int) }}'
loop:
- x86_64
- noarch

- name: install opencast testing repository
- name: Install opencast testing repository
ansible.builtin.yum_repository:
file: opencast-testing
name: opencast-testing-{{ item }}
description: Opencast RHEL $releasever Testing Repository - {{ item }}
baseurl: https://pkg.opencast.org/rpms/testing/el/$releasever/oc-{{ repository_version }}/{{ item }}
enabled: '{{ opencast_repository_enabled_testing }}'
name: "opencast-testing-{{ item }}"
description: "Opencast RHEL $releasever Testing Repository - {{ item }}"
baseurl: "https://pkg.opencast.org/rpms/testing/el/$releasever/oc-{{ repository_version }}/{{ item }}"
enabled: "{{ opencast_repository_enabled_testing }}"
gpgcheck: true
gpgkey: https://pkg.opencast.org/gpgkeys/opencast-{{ repository_version }}-rpm.key
gpgkey: "https://pkg.opencast.org/gpgkeys/opencast-{{ repository_version }}-rpm.key"
vars:
repository_version: '{{ "%02d" % (opencast_version_major|int) }}'
repository_version: "{{ '%02d' % (opencast_version_major | int) }}"
loop:
- x86_64
- noarch
# yamllint enable rule:line-length

- name: install epel repository
- name: Install epel repository
ansible.builtin.package:
name: epel-release

0 comments on commit e8749c1

Please sign in to comment.