marvinpinto.htpc
htpc
This is a tool for Ansible Galaxy that helps set up and manage a sample Home Theatre PC (HTPC) configuration.
The aim of this project is to show how Ansible can link together the necessary components for an HTPC setup, which has often been the most challenging part. Hopefully, this will simplify the process.
Features
- SABnzbd: A downloader for newsgroups.
- SickRage: A manager for TV show libraries.
- CouchPotato: A PVR and manager for movie libraries.
- Plex: A media server for movies, TV shows, music, and more.
- nginx: A frontend proxy using Google authentication (via OAuth2 Proxy).
- Designed to work together on an Ubuntu 14.04 server.
Pre-Requirements
You need a domain to host this setup. The example used is
htpc-sample.example.org
. Change thehtpc_dns_hostname
variable to your domain.The default setup uses Google authentication, so you must register an OAuth Web Application (find instructions here). Keep the Client ID and Client Secret, and set them as
htpc_oauth_client_id
andhtpc_oauth_client_secret
.You can also use other authentication providers; just update the
oauth2_proxy_cli_args
variable accordingly.Generate a random 32-byte string with:
$ date +%s | sha256sum | base64 | head -c 32 ; echo
Use this value as your
htpc_oauth_cookie_secret
.Get an HTTPS TLS certificate for your domain (
htpc_dns_hostname
). Update thehtpc_tls_cert
andhtpc_tls_cert_key
variables with your certificate and private key.
Role Variables
The HTPC-specific variables can be found in defaults/main.yml, while role-specific meta variables are in meta/main.yml.
Example
To install this module from Ansible Galaxy into the './roles' directory, run:
ansible-galaxy install marvinpinto.htpc -p ./roles
You can use it in a playbook like this:
- hosts: '127.0.0.1'
become: true
roles:
- role: 'marvinpinto.htpc'
htpc_dns_hostname: 'htpc-sample.example.org'
htpc_oauth_client_id: 'your-client-id'
htpc_oauth_client_secret: 'your-client-secret'
htpc_oauth_cookie_secret: 'N2U2NTI0NzljNjc2Y2VmNGVlZDZmMDg5'
htpc_authorized_users_emails: |
[email protected]
[email protected]
htpc_tls_cert: |
-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----
htpc_tls_cert_key: |
-----BEGIN RSA PRIVATE KEY-----
...
-----END RSA PRIVATE KEY-----
Post-setup Configuration
SABnzbd
Open your browser and go to
/sabnzbd
to start the setup wizard.In
/sabnzbd/config/general/
, you may want to Disable API-key since it’s behind OAuth2 Proxy.In
/sabnzbd/config/folders/
, set up:
- Temporary Download Folder:
/opt/downloads/sabnzbd-incomplete
- Completed Download Folder:
/opt/downloads/misc
- Permissions for completed downloads:
777
- Scripts folder:
/opt/nzbtomedia
- In
/sabnzbd/config/categories/
, for processing:
Movies:
- Category:
movies
- Script:
nzbToCouchPotato.py
- Folder/Path:
/opt/downloads/unprocessed/movies
- Category:
TV:
- Category:
tv
- Script:
nzbToSickBeard.py
- Folder/Path:
/opt/downloads/tv
- Category:
Audio:
- Category:
audio
- Script:
nzbToHeadPhones.py
- Folder/Path:
/opt/downloads/unprocessed/audio
- Category:
- In
/sabnzbd/config/switches/
, set:
- Action when encrypted RAR is downloaded:
abort
- Action when unwanted extension detected:
abort
- Unwanted extensions:
exe, com
- Post-Process Only Verified Jobs:
off
- Ignore Samples:
on
- Cleanup List:
nfo, sfv
- In
/sabnzbd/config/special/
, setempty_postproc
toon
.
SickRage
- Stop the SickRage service:
$ service sickrage stop
- Update settings to allow nginx to proxy requests:
$ sed -i 's/^web_root = ""/web_root = \/sickrage/g' /opt/config/sickrage-config/config.ini
$ sed -i 's/^handle_reverse_proxy = 0/handle_reverse_proxy = 1/g' /opt/config/sickrage-config/config.ini
- Change other settings:
$ sed -i 's/^use_failed_downloads = 0/use_failed_downloads = 1/g' /opt/config/sickrage-config/config.ini
$ sed -i 's/^log_nr = 5/log_nr = 1/g' /opt/config/sickrage-config/config.ini
$ sed -i 's/^auto_update =.*/auto_update = 0/g' /opt/config/sickrage-config/config.ini
$ sed -i 's/^version_notify =.*/version_notify = 0/g' /opt/config/sickrage-config/config.ini
$ sed -i 's/^naming_pattern =.*/naming_pattern = %S.N.S%0SE%0E.%E.N/g' /opt/config/sickrage-config/config.ini
$ sed -i 's/^web_host =.*/web_host = 127.0.0.1/g' /opt/config/sickrage-config/config.ini
- Start the SickRage service:
$ service sickrage start
CouchPotato
- Stop the CouchPotato service:
$ service couchpotato stop
- Update settings for nginx proxy:
$ sed -i 's/^url_base =.*/url_base = \/couchpotato/g' /opt/config/couchpotato-config/settings.conf
$ sed -i 's/^show_wizard =.*/show_wizard = 0/g' /opt/config/couchpotato-config/settings.conf
- Add this line to the
[core]
section in/opt/config/couchpotato-config/settings.conf
:
host = 127.0.0.1
- Start the CouchPotato service:
$ service couchpotato start
Go to
/couchpotato/settings/general
in your browser to disable periodic update checking.In
/couchpotato/settings/renamer
, enable movie renaming and make sure the folder paths are correct.Take note of your API Key and update
htpc_couchpotato_api_key
with this value.In
/couchpotato/settings/downloaders
, enable SABnzbd and set the host.
Plex Media Server
For the initial setup, create an SSH tunnel to your server as follows:
ssh ip.address.of.server -L 8888:localhost:32400
Then, access Plex at http://localhost:8888/web to complete the setup.
For a Vagrant environment, the SSH command will look like this:
ssh \
-p <Port> \
-i <IdentityFile> \
-L 8888:localhost:32400 \
<User>@<HostName>
Headphones
- Stop the Headphones service:
$ service headphones stop
- Configure nginx to proxy requests:
sed -i 's/^http_root =.*/http_root = \/headphones/g' /opt/config/headphones-config/config.ini
sed -i 's/^http_host =.*/http_host = 127.0.0.1/g' /opt/config/headphones-config/config.ini
Adjust the configuration settings as mentioned.
Finally, start the Headphones service:
$ service headphones start
Development
Use the provided Vagrantfile
for local development and testing:
$ vagrant up --provision
This is an Ansible Galaxy meta-role of sorts to install and manage a sample Home Theatre PC (HTPC) setup.
ansible-galaxy install marvinpinto.htpc