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

First batch of changes for PR #10

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
63 changes: 63 additions & 0 deletions roles/arrstack/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,66 @@ arrstack_volume_dir_group: "{{ arrstack_data_dir_group }}"
#
# * `arrstack_timezone` - Arr stack service timezone (e.g. `Etc/UTC`).
# Default: Use target host timezone.

###
##
## network_mode: will take precendence over ports:
##
services:
- service_name: sonarr
buildarr_managed: true
image: lscr.io/linuxserver/sonarr
image_tag: version-3.0.10.1567
container_name: sonarr
network_mode: service:gluetun
port_healthcheck: 8989
ports: [ 8989:8989/tcp ]
volumes: [ ./sonarr_config:/config ]
# depends_on: [ foo, bar ]
- service_name: radarr
buildarr_managed: true
image: lscr.io/linuxserver/radarr
image_tag: latest
container_name: radarr
network_mode: service:gluetun
port_healthcheck: 7878
ports: [ 7878:7878/tcp ]
volumes: [ ./radarr_config:/config ]
# depends_on: [ foo, bar ]
- service_name: prowlarr
buildarr_managed: true
image: lscr.io/linuxserver/prowlarr
image_tag: latest
container_name: prowlarr
network_mode: service:gluetun
port_healthcheck: 9696
ports: [ 9696:9696/tcp ]
volumes: [ ./prowlarr_config:/config ]
# depends_on: [ foo, bar ]
- service_name: transmission
buildarr_managed: false
image: '{{ arrstack_transmission_container_uri }}'
image_tag: '{{ arrstack_transmission_container_tag }}'
container_name: transmission
network_mode: service:gluetun
port_healthcheck: 9091
ports: [ 9091:9091/tcp ]
volumes: [ './transmission_config:/config', '{{ arrstack_data_dir }}/torrents:/data/torrents' ]
# depends_on: [ foo, bar ]
- service_name: flaresolverr
image: '{{ arrstack_flaresolverr_container_uri }}'
image_tag: '{{ arrstack_flaresolverr_container_tag }}'
container_name: flaresolverr
# network_mode:
port_healthcheck: 8191
ports: [ 8191:8191/tcp ]
# depends_on: [ foo, bar ]
- service_name: buildarr
buildarr_managed: false
image: '{{ arrstack_buildarr_container_uri }}'
image_tag: '{{ arrstack_buildarr_container_tag }}'
container_name: buildarr
network_mode: service:gluetun
# port_healthcheck:
# depends_on: [ prowlarr,sonarr ]
volumes: [ './buildarr_config:/config' ]
56 changes: 19 additions & 37 deletions roles/arrstack/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,82 +48,64 @@
- name: Create Docker Compose environment file
ansible.builtin.template:
src: docker-compose.yml.j2
dest: /opt/arrstack/docker-compose.yml
dest: "{{ arrstack_env_dir }}/docker-compose.yml"
owner: root
group: root
mode: 0600

- name: Start all Docker Compose services except for Buildarr
community.docker.docker_compose:
community.docker.docker_compose_v2:
project_name: arrstack
project_src: /opt/arrstack
services:
- transmission
- flaresolverr
- sonarr-hd
- sonarr-4k
- sonarr-anime
- prowlarr
project_src: "{{ arrstack_env_dir }}"
services: "{{ services | map(attribute='service_name') | list }}"

- name: Wait for all Docker Compose services to be accessible
ansible.builtin.uri:
url: "{{ item }}"
url: "http://localhost:{{ item.port_healthcheck }}"
status_code:
- 200
- 302
register: "arrstack_service_test"
until: "arrstack_service_test is not failed"
retries: 300
delay: 1
loop:
- "http://localhost:9091"
- "http://localhost:8191"
- "http://localhost:8989"
- "http://localhost:8990"
- "http://localhost:8991"
- "http://localhost:9696"
delay: 5
loop: "{{ services | selectattr('port_healthcheck', 'defined') | list }}"

- name: Fetch API keys for all Buildarr-managed instances
ansible.builtin.command:
argv:
- "sed"
- "-nE"
- 's,.*<ApiKey>([A-Za-z0-9]+)</ApiKey>.*,\1,p'
- "/opt/arrstack/{{ item }}/config.xml"
ansible.builtin.xml:
path: "{{ arrstack_env_dir }}/{{ item.service_name }}_config/config.xml"
xpath: "//ApiKey"
content: text
register: "arrstack_instance_apikeys_raw"
loop:
- sonarr-hd
- sonarr-4k
- sonarr-anime
- prowlarr
loop: "{{ services | selectattr('buildarr_managed', 'defined') | selectattr('buildarr_managed', 'equalto', true) | list }}"

- name: Parse Buildarr-managed instance API keys
ansible.builtin.set_fact:
arrstack_instance_apikeys: "{{ arrstack_instance_apikeys | default({}) | combine({item.item: item.stdout}) }}"
no_log: true
arrstack_instance_apikeys: "{{ arrstack_instance_apikeys | default({}) | combine({item.item.service_name: item.matches[0].ApiKey}) }}"
loop: "{{ arrstack_instance_apikeys_raw.results }}"
no_log: true

- name: Create Buildarr volume directory
ansible.builtin.file:
state: directory
path: /opt/arrstack/buildarr
path: "{{ arrstack_env_dir }}/buildarr_config"
owner: "{{ arrstack_volume_dir_owner }}"
group: "{{ arrstack_volume_dir_group }}"
mode: 0770

- name: Create Buildarr configuration files
ansible.builtin.template:
src: "{{ item }}.j2"
dest: "/opt/arrstack/buildarr/{{ item }}"
dest: "{{ arrstack_env_dir }}/buildarr_config/{{ item }}"
owner: root
group: "{{ arrstack_volume_dir_group }}"
mode: 0640
loop:
- buildarr.yml
- sonarr.yml
- buildarr.yml
- prowlarr.yml

- name: Start all Docker Compose services
community.docker.docker_compose:
community.docker.docker_compose_v2:
project_name: arrstack
project_src: /opt/arrstack
project_src: '{{ arrstack_env_dir }}'
173 changes: 45 additions & 128 deletions roles/arrstack/templates/docker-compose.yml.j2
Original file line number Diff line number Diff line change
@@ -1,135 +1,52 @@
---
# Arr application Docker Compose stack with configuration management using Buildarr.

version: "3.7"

services:

# Transmission instance for downloading torrents.
transmission:
image: "{{ arrstack_transmission_container_uri }}:{{ arrstack_transmission_container_tag }}"
hostname: transmission
restart: always
ports:
- 127.0.0.1:9091:9091
volumes:
- ./transmission:/config
- type: bind
source: "{{ arrstack_data_dir }}/torrents"
target: /data/torrents
environment:
TZ: "{{ arrstack_timezone }}"
PUID: "{{ arrstack_volume_dir_owner }}"
PGID: "{{ arrstack_volume_dir_group }}"
TRANSMISSION_WEB_HOME: "/flood-for-transmission/"
WHITELIST: "*.*.*.*"

# FlareSolverr instance for bypassing CloudFlare.
flaresolverr:
image: "{{ arrstack_flaresolverr_container_uri }}:{{ arrstack_flaresolverr_container_tag }}"
hostname: flaresolverr
restart: always
ports:
- 127.0.0.1:8191:8191
environment:
TZ: "{{ arrstack_timezone }}"
LOG_LEVEL: "info"

# Sonarr instance for grabbing HD/SD TV shows.
sonarr-hd:
image: "{{ arrstack_sonarr_container_uri }}:{{ arrstack_sonarr_container_tag }}"
hostname: sonarr-hd
restart: always
ports:
- 127.0.0.1:8989:8989
volumes:
- "./sonarr-hd:/config"
- type: bind
source: "{{ arrstack_data_dir }}"
target: /data
environment:
TZ: "{{ arrstack_timezone }}"
PUID: "{{ arrstack_volume_dir_owner }}"
PGID: "{{ arrstack_volume_dir_group }}"
depends_on:
- transmission

# Sonarr instance for grabbing 4K TV shows.
sonarr-4k:
image: "{{ arrstack_sonarr_container_uri }}:{{ arrstack_sonarr_container_tag }}"
hostname: sonarr-4k
restart: always
{% include 'gluetun.j2' ignore missing %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please include a way to disable including this using the Ansible inventory?

For example, I host my *Arrs on a NAS in my home, and don't need to setup VPNs to access it (and even then, I actually have a separate setup for all that).


{%+ for item in services %}
{{ item.service_name }}:
image: {{ item.image}}:{{ item.image_tag }}
container_name: {{ item.container_name }}
{% if item.network_mode is defined %}
network_mode: {{ item.network_mode }}
{%- endif %}
{% if item.hostname is defined %}
hostname:
{%- endif %}
{% if item.network_mode is defined %}
{% else %}
{% if item.ports is defined %}
ports:
- 127.0.0.1:8990:8989
volumes:
- "./sonarr-4k:/config"
- type: bind
source: "{{ arrstack_data_dir }}"
target: /data
environment:
TZ: "{{ arrstack_timezone }}"
PUID: "{{ arrstack_volume_dir_owner }}"
PGID: "{{ arrstack_volume_dir_group }}"
depends_on:
- transmission
{% for port in item.ports %}
- {{ port }}
{% endfor %}
{% endif %}
{% endif %}

# Sonarr instance for grabbing anime series.
sonarr-anime:
image: "{{ arrstack_sonarr_container_uri }}:{{ arrstack_sonarr_container_tag }}"
hostname: sonarr-anime
restart: always
ports:
- 127.0.0.1:8991:8989
{% if item.volumes is defined %}
volumes:
- "./sonarr-anime:/config"
- type: bind
source: "{{ arrstack_data_dir }}"
target: /data
{% for volume in item.volumes %}
- {{ volume }}
{% endfor %}
{% endif %}
environment:
TZ: "{{ arrstack_timezone }}"
PUID: "{{ arrstack_volume_dir_owner }}"
PGID: "{{ arrstack_volume_dir_group }}"
- TZ="{{ arrstack_timezone }}"
- UID="{{ arrstack_volume_dir_owner }}"
- GID="{{ arrstack_volume_dir_group }}"
{%if item.depends_on is defined %}
depends_on:
- transmission

# Prowlarr instance for managing indexers.
prowlarr:
image: "{{ arrstack_prowlarr_container_uri }}:{{ arrstack_prowlarr_container_tag }}"
hostname: prowlarr
{% endif %}
{% if item.depends_on is defined %}
{% for dependency in item.depends_on %}
{{ dependency }}:
condition: service_healthy
{% endfor %}
{%- endif %}
{% if item.port_healthcheck is defined %}
healthcheck:
test: curl --silent --fail localhost:{{ item.port_healthcheck}} || exit 1
interval: 10s
retries: 3
start_period: 5s
timeout: 5s
{% endif %}
restart: always
ports:
- 127.0.0.1:9696:9696
volumes:
- "./prowlarr:/config"
- type: bind
source: "{{ arrstack_data_dir }}"
target: /data
environment:
TZ: "{{ arrstack_timezone }}"
PUID: "{{ arrstack_volume_dir_owner }}"
PGID: "{{ arrstack_volume_dir_group }}"
depends_on:
- transmission
- flaresolverr
- sonarr-hd
- sonarr-4k
- sonarr-anime

# Buildarr instance for managing instance configurations.
buildarr:
image: "{{ arrstack_buildarr_container_uri }}:{{ arrstack_buildarr_container_tag }}"
hostname: buildarr
restart: always
volumes:
- type: bind
source: ./buildarr
target: /config
environment:
TZ: "{{ arrstack_timezone }}"
PUID: "{{ arrstack_volume_dir_owner }}"
PGID: "{{ arrstack_volume_dir_group }}"
depends_on:
- sonarr-hd
- sonarr-4k
- sonarr-anime
- prowlarr
{% endfor %}
Loading