Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add role: Membarr #257

Merged
merged 4 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions defaults/settings.yml.default
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ handbrake:
handbrake_pass: saltbox
invoiceninja:
app_key: 'base64:O1S3kAJEDgo92gPkXtxfdCJpoGShgKloUSdcaHMXmoY='
membarr:
discord_token: your_discord_bot_token
moviematch:
libraries: Movies
plex_url: http://plex:32400
Expand Down
116 changes: 116 additions & 0 deletions roles/membarr/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
##########################################################################
# Title: Sandbox: Membarr | Default Variables #
# Author(s): CHAIR/Raneydazed #
# URL: https://github.com/saltyorg/Sandbox #
# -- #
##########################################################################
# GNU General Public License v3.0 #
##########################################################################
---
################################
# Basics
################################

membarr_name: membarr

################################
# Paths
################################

membarr_paths_folder: "{{ membarr_name }}"
membarr_paths_location: "{{ server_appdata_path }}/{{ membarr_paths_folder }}"
membarr_paths_recursive: true
membarr_paths_config_location: "{{ membarr_paths_location }}/config.ini"
membarr_paths_folders_list:
- "{{ membarr_paths_location }}"

################################
# Docker
################################

# Container
membarr_docker_container: "{{ membarr_name }}"

# Image
membarr_docker_image_pull: true
membarr_docker_image_tag: "latest"
membarr_docker_image: "yoruio/membarr:{{ membarr_docker_image_tag }}"

# Ports
membarr_docker_ports_defaults: []
membarr_docker_ports_custom: []
membarr_docker_ports: "{{ membarr_docker_ports_defaults
+ membarr_docker_ports_custom }}"

# Envs
membarr_docker_envs_default:
TZ: "{{ tz }}"
token: "{{ membarr.discord_token }}"
membarr_docker_envs_custom: {}
membarr_docker_envs: "{{ membarr_docker_envs_default
| combine(membarr_docker_envs_custom) }}"

# Commands
membarr_docker_commands_default: []
membarr_docker_commands_custom: []
membarr_docker_commands: "{{ membarr_docker_commands_default
+ membarr_docker_commands_custom }}"

# Volumes
membarr_docker_volumes_default:
- "{{ membarr_paths_location }}:/app/app/config"
membarr_docker_volumes_custom: []
membarr_docker_volumes: "{{ membarr_docker_volumes_default
+ membarr_docker_volumes_custom }}"

# Devices
membarr_docker_devices_default: []
membarr_docker_devices_custom: []
membarr_docker_devices: "{{ membarr_docker_devices_default
+ membarr_docker_devices_custom }}"

# Hosts
membarr_docker_hosts_default: []
membarr_docker_hosts_custom: []
membarr_docker_hosts: "{{ docker_hosts_common
| combine(membarr_docker_hosts_default)
| combine(membarr_docker_hosts_custom) }}"

# Labels
membarr_docker_labels_default: {}
membarr_docker_labels_custom: {}
membarr_docker_labels: "{{ docker_labels_common
| combine(membarr_docker_labels_default)
| combine(membarr_docker_labels_custom) }}"

# Hostname
membarr_docker_hostname: "{{ membarr_name }}"

# Networks
membarr_docker_networks_alias: "{{ membarr_name }}"
membarr_docker_networks_default: []
membarr_docker_networks_custom: []
membarr_docker_networks: "{{ docker_networks_common
+ membarr_docker_networks_default
+ membarr_docker_networks_custom }}"

# Capabilities
membarr_docker_capabilities_default: []
membarr_docker_capabilities_custom: []
membarr_docker_capabilities: "{{ membarr_docker_capabilities_default
+ membarr_docker_capabilities_custom }}"

# Security Opts
membarr_docker_security_opts_default: []
membarr_docker_security_opts_custom: []
membarr_docker_security_opts: "{{ membarr_docker_security_opts_default
+ membarr_docker_security_opts_custom }}"

# Restart Policy
membarr_docker_restart_policy: always

# State
membarr_docker_state: started

# User
membarr_docker_user: "{{ uid }}:{{ gid }}"
27 changes: 27 additions & 0 deletions roles/membarr/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#########################################################################
# Title: Sandbox: Membarr #
# Author(s): CHAIR/Raneydazed #
# URL: https://github.com/saltyorg/Sandbox #
# -- #
#########################################################################
# GNU General Public License v3.0 #
#########################################################################
---

- name: Fail when default membarr.discord_token is specified
ansible.builtin.fail:
msg: "You must specify a Discord bot token in the settings under membarr.discord_token."
when: (membarr.discord_token == 'your_discord_bot_token') and
(not continuous_integration)

- name: Remove existing Docker container
ansible.builtin.include_tasks: "{{ resources_tasks_path }}/docker/remove_docker_container.yml"

- name: Create directories
ansible.builtin.include_tasks: "{{ resources_tasks_path }}/directories/create_directories.yml"

- name: Import Settings task
ansible.builtin.import_tasks: "subtasks/settings.yml"

- name: Create Docker container
ansible.builtin.include_tasks: "{{ resources_tasks_path }}/docker/create_docker_container.yml"
63 changes: 63 additions & 0 deletions roles/membarr/tasks/subtasks/settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
##########################################################################
# Title: Sandbox: Membarr #
# Author(s): CHAIR/Raneydazed #
# URL: https://github.com/saltyorg/Sandbox #
# -- #
##########################################################################
# GNU General Public License v3.0 #
##########################################################################
---
- name: Set Default Plex instance
ansible.builtin.set_fact:
plex_name: "{{ plex_instances[0] }}"
when: not plex_name is defined

# Plex Tasks

- name: "Settings | Check if '{{ plex_paths_config_location | basename }}' exists"
ansible.builtin.stat:
path: "{{ plex_paths_config_location }}"
register: preferences_xml

- name: Settings | {{ plex_name }} info tasks
block:

- name: Settings | Fetch {{ plex_name }} info
community.general.xml:
path: "{{ plex_paths_config_location }}"
xpath: /Preferences
content: attribute
register: preferences_xml_resp
ignore_errors: true

- name: Settings | Register {{ plex_name }} Auth Token Value
ansible.builtin.set_fact:
plex_auth_token: "{{ preferences_xml_resp.matches[0].Preferences.PlexOnlineToken }}"

- name: Settings | Register {{ plex_name }} Friendly Server Name
ansible.builtin.set_fact:
plex_friendly_name: "{{ preferences_xml_resp.matches[0].Preferences.FriendlyName }}"

- name: Settings | Register {{ plex_name }} User Name
ansible.builtin.set_fact:
plex_online_username: "{{ preferences_xml_resp.matches[0].Preferences.PlexOnlineUsername }}"

when: preferences_xml.stat.exists

- name: Settings | Check if `{{ membarr_paths_config_location | basename }}` exists
ansible.builtin.stat:
path: "{{ membarr_paths_config_location }}"
register: membarr_config

- name: Settings | New `{{ membarr_paths_config_location | basename }}` tasks
block:

- name: Settings | Import default `{{ membarr_paths_config_location | basename }}`
ansible.builtin.template:
src: config.ini.j2
dest: "{{ membarr_paths_config_location }}"
owner: "{{ user.name }}"
group: "{{ user.name }}"
mode: 0775

when: not membarr_config.stat.exists
12 changes: 12 additions & 0 deletions roles/membarr/templates/config.ini.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[bot_envs]
Discord_bot_token = {{ membarr.discord_token }}
{% if plex_auth_token is defined %}
plex_base_url = {{ plex_web_url }}
plex_token = {{ plex_auth_token }}
plex_server_name = {{ plex_friendly_name }}
plex_user = {{ plex_online_username }}
{% endif %}
plex_pass =
plex_enabled = True
plex_libs = all
plex_roles = Add To Plex