Skip to content
Snippets Groups Projects
Verified Commit b387b2d9 authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Added tests and tasks to install dependencies and configure DB

parent 288df7e5
No related branches found
No related tags found
No related merge requests found
---
# defaults file for funkwhale
funkwhale_install_path: /srv/funkwhale
funkwhale_data_path: /srv/funkwhale/data
funkwhale_username: funkwhale
funkwhale_database_managed: true
funkwhale_database_name: funkwhale
funkwhale_database_user: funkwhale
funkwhale_nginx_managed: true
funkwhale_redis_managed: true
---
galaxy_info:
author: your name
description: your description
company: your company (optional)
author: Eliot Berriot
description: An ansible role to install a Funkwhale server (https://funkwhale.audio)
company: Funkwhale
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
......@@ -15,9 +15,9 @@ galaxy_info:
# - GPLv3
# - Apache
# - CC-BY
license: license (GPLv2, CC-BY, etc)
license: AGPLv3
min_ansible_version: 1.2
min_ansible_version: 2.7
# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
......@@ -33,11 +33,11 @@ galaxy_info:
#
# platforms is a list of platforms, and each platform has a name and a list of versions.
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
platforms:
- name: Debian
versions:
- all
- 9
# - name: SomePlatform
# versions:
# - all
......
......@@ -7,7 +7,14 @@ lint:
name: yamllint
platforms:
- name: instance
image: debian:9
image: alehaa/debian-systemd:stretch
command: /sbin/init
tmpfs:
- /run
- /tmp
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
provisioner:
name: ansible
lint:
......@@ -16,3 +23,4 @@ verifier:
name: testinfra
lint:
name: flake8
enabled: False
Source diff could not be displayed: it is too large. Options to address this: view the blob.
import os
import pytest
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
os.environ["MOLECULE_INVENTORY_FILE"]
).get_hosts("all")
def test_hosts_file(host):
f = host.file('/etc/hosts')
f = host.file("/etc/hosts")
assert f.exists
assert f.user == 'root'
assert f.group == 'root'
assert f.user == "root"
assert f.group == "root"
@pytest.mark.parametrize(
"package",
[
"python3",
"python3-dev",
"python3-pip",
"python3-venv",
"libldap2-dev",
"libsasl2-dev",
"git",
"unzip",
"build-essential",
"ffmpeg",
"libjpeg-dev",
"libmagic-dev",
"libpq-dev",
"postgresql-client",
],
)
def test_installed_mandatory_packages(host, package):
package = host.package(package)
assert package.is_installed
@pytest.mark.parametrize("service", ["redis-server", "postgresql", "nginx"])
def test_installed_services(host, service):
service = host.service(service)
assert service.is_running
assert service.is_enabled
def test_database_created(host):
cmd = """
sudo -u postgres psql -A -t -c \
"SELECT 1 FROM pg_catalog.pg_user u WHERE u.usename = 'funkwhale';"
"""
result = host.run(cmd)
assert result.stdout == "1"
def test_database_user_created(host):
cmd = """
sudo -u postgres psql -A -t -c "SELECT 1 FROM pg_database WHERE datname = 'funkwhale';"
"""
result = host.run(cmd)
assert result.stdout == "1"
---
- name: "Install postgresql"
become: true
when: funkwhale_database_managed
package:
name:
- postgresql
- python-psycopg2
- name: "Start Postgresql"
when: funkwhale_database_managed
service:
name: postgresql
state: started
- name: "Create {{ funkwhale_database_name }} database"
become: true
become_user: postgres
when: funkwhale_database_managed
postgresql_db:
name: "{{ funkwhale_database_name }}"
encoding: UTF-8
- name: "Create {{ funkwhale_database_user }} database user"
become: true
become_user: postgres
when: funkwhale_database_managed
postgresql_user:
db: "{{ funkwhale_database_name }}"
name: "{{ funkwhale_database_user }}"
---
# tasks file for funkwhale
- name: Molecule Hello World!
debug:
msg: Hello, World!
- include: packages.yml
- include: db.yml
- include: redis.yml
- include: nginx.yml
---
- name: "Install nginx"
become: true
when: funkwhale_nginx_managed
package:
name:
- nginx
- name: "Start Nginx"
when: funkwhale_nginx_managed
service:
name: nginx
state: started
---
- name: "Install system packages"
become: true
package:
name:
- "python3"
- "python3-dev"
- "python3-pip"
- "python3-venv"
- "libldap2-dev"
- "libsasl2-dev"
- "git"
- "unzip"
- "build-essential"
- "ffmpeg"
- "libjpeg-dev"
- "libmagic-dev"
- "libpq-dev"
- "postgresql-client"
---
- name: "Install redis"
become: true
when: funkwhale_redis_managed
package:
name:
- redis-server
- name: "Start redis-server"
when: funkwhale_redis_managed
service:
name: redis-server
state: started
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment