Browse Source

create supysonic role

master
vincent 2 years ago
commit
6010d2aa4f
  1. 18
      defaults/main.yml
  2. 22
      handlers/main.yml
  3. 61
      meta/main.yml
  4. 84
      tasks/main.yml
  5. 63
      templates/supysonic.j2
  6. 15
      templates/systemd/gunicorn.service.j2
  7. 2
      vars/main.yml

18
defaults/main.yml

@ -0,0 +1,18 @@
---
# defaults file for supysonic
supysonic_name: supysonic
source_location: /srv/
venv_location: /opt/venv/
supysonic_venv_name: "{{supysonic_name}}"
exec_user: root
exec_group: root
supysonic_repo: https://github.com/spl0k/supysonic.git
supysonic_force_site_update: false
supysonic_repo_branch: master
supysonic_db_user: supysonic
# Database password, please change when using the role
supysonic_db_password: supysonic
# Database name
supysonic_db_name: supysonic

22
handlers/main.yml

@ -0,0 +1,22 @@
---
# handlers file for chainetv
- name: Reload systemd
systemd:
daemon_reload: yes
become: yes
- name: ensure socket is start
systemd:
name: "gunicorn-{{supysonic_name}}.socket" # not required. Name of the service. When using in a chroot environment you always need to specify the full name i.e. (crond.service).
enabled: true # not required. Whether the service should start on boot. B(At least one of state and enabled are required.)
state: restarted # not required. choices: reloaded;restarted;started;stopped. C(started)/C(stopped) are idempotent actions that will not run commands unless necessary. C(restarted) will always bounce the service. C(reloaded) will always reload.
become: yes
- name: restart supysonic service
systemd:
name: "gunicorn-{{supysonic_name}}.service" # not required. Name of the service. When using in a chroot environment you always need to specify the full name i.e. (crond.service).
state: restarted # not required. choices: reloaded;restarted;started;stopped. C(started)/C(stopped) are idempotent actions that will not run commands unless necessary. C(restarted) will always bounce the service. C(reloaded) will always reload.
enabled: true
become: yes

61
meta/main.yml

@ -0,0 +1,61 @@
galaxy_info:
author: your name
description: your description
company: your company (optional)
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker
# Some suggested licenses:
# - BSD (default)
# - MIT
# - GPLv2
# - GPLv3
# - Apache
# - CC-BY
license: license (GPLv2, CC-BY, etc)
min_ansible_version: 2.4
# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
# Optionally specify the branch Galaxy will use when accessing the GitHub
# repo for this role. During role install, if no tags are available,
# Galaxy will use this branch. During import Galaxy will access files on
# this branch. If Travis integration is configured, only notifications for this
# branch will be accepted. Otherwise, in all cases, the repo's default branch
# (usually master) will be used.
#github_branch:
#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99
galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.
dependencies:
- {role: mariadb, become: yes }
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.

84
tasks/main.yml

@ -0,0 +1,84 @@
---
# tasks file for chainetv
- name: "Ensure database is present"
become: yes
mysql_db:
name: "{{ supysonic_db_name }}"
collation: utf8_general_ci
encoding: utf8
state: present
register: ttrss_database_creation
- name: "Ensure db user is present"
become: yes
mysql_user:
name: "{{ supysonic_db_user }}"
host: localhost
password: "{{ supysonic_db_password }}"
priv: "{{ supysonic_db_name }}.*:ALL"
state: present
- name: stat location folder
stat:
path: "{{source_location}}/{{supysonic_name}}" # required. The full path of the file/object to get the facts of.
register: location_stat
- name: install source file if not exist
git:
dest: "{{source_location}}/{{supysonic_name}}" # required. The path of where the repository should be checked out. This parameter is required, unless C(clone) is set to C(no).
repo: "{{supysonic_repo}}" # required. git, SSH, or HTTP(S) protocol address of the git repository.
clone: yes # not required. If C(no), do not clone the repository if it does not exist locally
version: "{{supysonic_repo_branch}}"
become: yes
when: location_stat.stat.exists == false or supysonic_force_site_update == true
- name: create folder in var
file:
path: "/var/{{supysonic_name}}" # required. Path to the file being managed.
state: directory # not required. choices: absent;directory;file;hard;link;touch. If C(directory), all intermediate subdirectories will be created if they do not exist. Since Ansible 1.7 they will be created with the supplied permissions. If C(file), the file will NOT be created if it does not exist; see the C(touch) value or the M(copy) or M(template) module if you want that behavior. If C(link), the symbolic link will be created or changed. Use C(hard) for hardlinks. If C(absent), directories will be recursively deleted, and files or symlinks will be unlinked. Note that C(absent) will not cause C(file) to fail if the C(path) does not exist as the state did not change. If C(touch) (new in 1.4), an empty file will be created if the C(path) does not exist, while an existing file or directory will receive updated file access and modification times (similar to the way `touch` works from the command line).
become: yes
- name: ensure venv folder exist
file:
name: "{{venv_location}}"
state: directory
mode: 0777
become: yes
- name: create venv
pip:
name: "file://{{source_location}}/{{supysonic_name}}"
virtualenv: "{{venv_location}}{{supysonic_venv_name}}"
virtualenv_command: /usr/bin/python -m venv
- name: install sql client
pip:
virtualenv: "{{venv_location}}{{supysonic_venv_name}}" # not required. An optional path to a I(virtualenv) directory to install into. It cannot be specified together with the 'executable' parameter (added in 2.1). If the virtualenv does not exist, it will be created before installing packages. The optional virtualenv_site_packages, virtualenv_command, and virtualenv_python options affect the creation of the virtualenv.
name: pymysql
- name: apply systemd service template
template:
dest: "/etc/supysonic" # required. Location to render the template to on the remote machine.
src: "supysonic.j2" # required. Path of a Jinja2 formatted template on the Ansible controller. This can be a relative or absolute path.
become: yes
notify:
- restart supysonic service
- name: install gunicorn
pip:
virtualenv: "{{venv_location}}{{supysonic_venv_name}}" # not required. An optional path to a I(virtualenv) directory to install into. It cannot be specified together with the 'executable' parameter (added in 2.1). If the virtualenv does not exist, it will be created before installing packages. The optional virtualenv_site_packages, virtualenv_command, and virtualenv_python options affect the creation of the virtualenv.
name: gunicorn # not required. The name of a Python library to install or the url(bzr+,hg+,git+,svn+) of the remote package.,This can be a list (since 2.2) and contain version specifiers (since 2.7).
- name: apply systemd service template
template:
dest: "/etc/systemd/system/gunicorn-{{supysonic_name}}.service" # required. Location to render the template to on the remote machine.
src: "systemd/gunicorn.service.j2" # required. Path of a Jinja2 formatted template on the Ansible controller. This can be a relative or absolute path.
become: yes
notify:
- Reload systemd
- restart supysonic service

63
templates/supysonic.j2

@ -0,0 +1,63 @@
[base]
; A database URI. See the 'schema' folder for schema creation scripts
; Default: sqlite:////tmp/supysonic/supysonic.db
;database_uri = sqlite:////var/supysonic/supysonic.db
database_uri = mysql://{{supysonic_db_user}}:{{supysonic_db_password}}@localhost/{{supysonic_db_name}}
;database_uri = postgres://supysonic:supysonic@localhost/supysonic
; Optional, restrict scanner to these extensions. Default: none
;scanner_extensions = mp3 ogg
[webapp]
; Optional cache directory. Default: /tmp/supysonic
cache_dir = /var/supysonic/cache
; Main cache max size in MB. Default: 512
cache_size = 512
; Transcode cache max size in MB. Default: 1024 (1GB)
transcode_cache_size = 1024
; Optional rotating log file. Default: none
log_file = /var/supysonic/supysonic.log
; Log level. Possible values: DEBUG, INFO, WARNING, ERROR, CRITICAL. Default: WARNING
log_level = WARNING
; Enable the Subsonic REST API. You'll most likely want to keep this on, here for testing purposes. Default: on
;mount_api = on
; Enable the administrative web interface. Default: on
;mount_webui = on
[daemon]
; Delay before triggering scanning operation after a change have been detected
; This prevents running too many scans when multiple changes are detected for a
; single file over a short time span. Default: 5
wait_delay = 5
; Optional rotating log file for the scanner daemon. Logs to stderr if empty
log_file = /var/supysonic/supysonic-daemon.log
log_level = INFO
[lastfm]
; API and secret key to enable scrobbling. http://www.last.fm/api/accounts
; Defaults: none
;api_key =
;secret =
[transcoding]
; Programs used to convert from one format/bitrate to another. Defaults: none
transcoder_mp3_mp3 = lame --quiet --mp3input -b %outrate %srcpath -
transcoder = ffmpeg -i %srcpath -ab %outratek -v 0 -f %outfmt -
decoder_mp3 = mpg123 --quiet -w - %srcpath
decoder_ogg = oggdec -o %srcpath
decoder_flac = flac -d -c -s %srcpath
encoder_mp3 = lame --quiet -b %outrate - -
encoder_ogg = oggenc2 -q -M %outrate -
[mimetypes]
; Extension to mimetype mappings in case your system has some trouble guessing
; Default: none
;mp3 = audio/mpeg
;ogg = audio/vorbis

15
templates/systemd/gunicorn.service.j2

@ -0,0 +1,15 @@
[Unit]
Description=gunicorn daemon for {{supysonic_name}}
After=network.target
[Service]
PIDFile=/run/gunicorn-{{supysonic_name}}/pid
User={{exec_user}}
Group={{exec_group}}
RuntimeDirectory=gunicorn
WorkingDirectory={{source_location}}/{{supysonic_name}}/cgi-bin
ExecStart={{venv_location}}{{supysonic_venv_name}}/bin/gunicorn -b 0.0.0.0:8001 --workers=4 --pid /run/gunicorn-{{supysonic_name}}/pid server:app
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
PrivateTmp=true

2
vars/main.yml

@ -0,0 +1,2 @@
---
# vars file for chainetv
Loading…
Cancel
Save