From f1c2141336dda8e0eef054dd5b796d4d63fc6f05 Mon Sep 17 00:00:00 2001 From: RaneyDazed Date: Tue, 9 May 2023 00:46:58 -0500 Subject: [PATCH 1/4] Create Membarr Docker Container with Default Variables The code changes include the addition of Membarr's default variables and the creation/removal of Docker container directories, and creating the Docker container. --- roles/membarr/defaults/main.yml | 117 ++++++++++++++++++++++++++++++++ roles/membarr/tasks/main.yml | 18 +++++ 2 files changed, 135 insertions(+) create mode 100644 roles/membarr/defaults/main.yml create mode 100644 roles/membarr/tasks/main.yml diff --git a/roles/membarr/defaults/main.yml b/roles/membarr/defaults/main.yml new file mode 100644 index 0000000000..64d5d070b1 --- /dev/null +++ b/roles/membarr/defaults/main.yml @@ -0,0 +1,117 @@ +# docker run -d --restart unless-stopped --name membarr -v /[path to config]:/app/app/config -e "token=YOUR_DISCORD_TOKEN_HERE" yoruio/membarr:latest + + +########################################################################## +# 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_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: "insert_bot_token_here" +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 }}" diff --git a/roles/membarr/tasks/main.yml b/roles/membarr/tasks/main.yml new file mode 100644 index 0000000000..2e9840388d --- /dev/null +++ b/roles/membarr/tasks/main.yml @@ -0,0 +1,18 @@ +######################################################################### +# Title: Sandbox: Membarr # +# Author(s): CHAIR/Raneydazed # +# URL: https://github.com/saltyorg/Sandbox # +# -- # +######################################################################### +# GNU General Public License v3.0 # +######################################################################### +--- + +- 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: Create Docker container + ansible.builtin.include_tasks: "{{ resources_tasks_path }}/docker/create_docker_container.yml" From 8aea4f5a5a2b3e9b77592f495cfc5773e064e4b0 Mon Sep 17 00:00:00 2001 From: RaneyDazed Date: Tue, 9 May 2023 00:50:18 -0500 Subject: [PATCH 2/4] Add discord token to Membarr configuration in settings.yml.default This commit adds a discord_token field to Membarr settings in defaults/settings.yml.default file. The configuration change enables users to set up their Discord bot token in Membarr. --- defaults/settings.yml.default | 2 ++ 1 file changed, 2 insertions(+) diff --git a/defaults/settings.yml.default b/defaults/settings.yml.default index eee7dc5d64..c5257ff101 100644 --- a/defaults/settings.yml.default +++ b/defaults/settings.yml.default @@ -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 From cb455d81804bb429db0dfa84ab2655bc998e0e30 Mon Sep 17 00:00:00 2001 From: RaneyDazed Date: Tue, 9 May 2023 02:12:33 -0500 Subject: [PATCH 3/4] "Refactor membarr (main): Update default Discord token usage" This commit refactors the membarr application to use the default Discord token. The docker run command has been updated to include new environment variables, and the role's main task now checks for a specified default Discord token and fails when not specified. --- roles/membarr/defaults/main.yml | 5 +---- roles/membarr/tasks/main.yml | 6 ++++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/roles/membarr/defaults/main.yml b/roles/membarr/defaults/main.yml index 64d5d070b1..acc3648c87 100644 --- a/roles/membarr/defaults/main.yml +++ b/roles/membarr/defaults/main.yml @@ -1,6 +1,3 @@ -# docker run -d --restart unless-stopped --name membarr -v /[path to config]:/app/app/config -e "token=YOUR_DISCORD_TOKEN_HERE" yoruio/membarr:latest - - ########################################################################## # Title: Sandbox: Membarr | Default Variables # # Author(s): CHAIR/Raneydazed # @@ -46,7 +43,7 @@ membarr_docker_ports: "{{ membarr_docker_ports_defaults # Envs membarr_docker_envs_default: TZ: "{{ tz }}" - token: "insert_bot_token_here" + token: "{{ membarr.discord_token }}" membarr_docker_envs_custom: {} membarr_docker_envs: "{{ membarr_docker_envs_default | combine(membarr_docker_envs_custom) }}" diff --git a/roles/membarr/tasks/main.yml b/roles/membarr/tasks/main.yml index 2e9840388d..24f9ba647f 100644 --- a/roles/membarr/tasks/main.yml +++ b/roles/membarr/tasks/main.yml @@ -8,6 +8,12 @@ ######################################################################### --- +- 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" From 141d58090ca38b0e3ea880edcee7e8f136fc2966 Mon Sep 17 00:00:00 2001 From: CHAIR Date: Mon, 24 Jul 2023 18:06:06 +0000 Subject: [PATCH 4/4] feat: Add membarr_paths_recursive and membarr_paths_config_location - Added membarr_paths_recursive variable to allow recursive creation of directories in membarr role. - Added membarr_paths_config_location variable to specify the location of config.ini file in membarr role. - Created new subtask settings.yml to handle all the settings related tasks in membarr role. - Added import task to include the settings.yml subtask in the main tasks of membarr role. - Created config.ini.j2 template file to define the configuration options for membarr. --- roles/membarr/defaults/main.yml | 2 + roles/membarr/tasks/main.yml | 3 ++ roles/membarr/tasks/subtasks/settings.yml | 63 +++++++++++++++++++++++ roles/membarr/templates/config.ini.j2 | 12 +++++ 4 files changed, 80 insertions(+) create mode 100644 roles/membarr/tasks/subtasks/settings.yml create mode 100644 roles/membarr/templates/config.ini.j2 diff --git a/roles/membarr/defaults/main.yml b/roles/membarr/defaults/main.yml index acc3648c87..81292a1e77 100644 --- a/roles/membarr/defaults/main.yml +++ b/roles/membarr/defaults/main.yml @@ -19,6 +19,8 @@ membarr_name: membarr 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 }}" diff --git a/roles/membarr/tasks/main.yml b/roles/membarr/tasks/main.yml index 24f9ba647f..59c92006a1 100644 --- a/roles/membarr/tasks/main.yml +++ b/roles/membarr/tasks/main.yml @@ -20,5 +20,8 @@ - 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" diff --git a/roles/membarr/tasks/subtasks/settings.yml b/roles/membarr/tasks/subtasks/settings.yml new file mode 100644 index 0000000000..490eb745ec --- /dev/null +++ b/roles/membarr/tasks/subtasks/settings.yml @@ -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 diff --git a/roles/membarr/templates/config.ini.j2 b/roles/membarr/templates/config.ini.j2 new file mode 100644 index 0000000000..d38d2ea81f --- /dev/null +++ b/roles/membarr/templates/config.ini.j2 @@ -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