Skip to content

Commit

Permalink
Homer config is now generated by Ansible
Browse files Browse the repository at this point in the history
Homer now parses the defaults/main.yml files inside of the subdirectories in the 'containers' folder for variables called 'homer_url', 'homer_category' and 'homer_name'. If 'homer_url' is present, the app will be shown on the Homer dashboard.\n You will also need to place an icon file with the same name as the app's folder in the 'containers' directory
  • Loading branch information
notthebee committed Oct 7, 2021
1 parent 4007fe7 commit b584cd1
Show file tree
Hide file tree
Showing 42 changed files with 378 additions and 26 deletions.
18 changes: 15 additions & 3 deletions group_vars/all/vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ msmtp_accounts:
auth: "on"
from: "{{ email }}"
user: "{{ email }}"
password: "{{ email_password}}"
password: "{{ email_password }}"

msmtp_default_account: "mailbox"

Expand All @@ -95,13 +95,23 @@ copy_persistent_data: false

force_copy_persistent_data: false

enable_smarthome: true
enable_deconz: true

enable_homeassistant: true

enable_plex: false

enable_jellyfin: true

enable_downloaders: true
enable_unifi: false

enable_authelia: true

enable_sonarr: true

enable_radarr: true

enable_jackett: true

enable_deluge: true

Expand All @@ -121,6 +131,8 @@ enable_wireguard: true

enable_ikev2: true

enable_watchtower: true

#
# Time Machine
#
Expand Down
2 changes: 2 additions & 0 deletions roles/containers/authelia/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
container_name: authelia
52 changes: 52 additions & 0 deletions roles/containers/authelia/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---

- name: Make sure the {{ container_name }} container is created and running
docker_container:
name: "{{ container_name }}"
image: "authelia/authelia:latest"
pull: true
state: 'started'
env:
TZ: "{{ timezone }}"
volumes:
- "{{ docker_dir }}/{{ container_name }}:/config"
restart_policy: unless-stopped
register: container

- name: Add {{ container_name }} to the SWAG network (reverse-proxy)
docker_network:
name: swag_network
connected:
- "{{ container_name }}"
appends: yes
when: enable_swag


- name: Create the configuration directory
file:
path: "{{ docker_dir }}/{{ container_name }}"
state: directory
owner: "{{ username }}"
group: "{{ username }}"

- name: Install the configuration template
template:
src: configuration.yml.j2
dest: "{{ docker_dir }}/{{ container_name }}/configuration.yml"
owner: "{{ username }}"
group: "{{ username }}"
register: configuration

- name: Install the users template
template:
src: users_database.yml.j2
dest: "{{ docker_dir }}/{{ container_name }}/users_database.yml"
owner: "{{ username }}"
group: "{{ username }}"
register: users

- name: Restart the docker container on change
docker_container:
name: "{{ container_name }}"
restart: yes
when: container.changed or configuration.changed or users.changed
49 changes: 49 additions & 0 deletions roles/containers/authelia/templates/configuration.yml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
server.host: 0.0.0.0
server.port: 9091
theme: dark
server:
read_buffer_size: 4096
write_buffer_size: 4096
path: "authelia"
jwt_secret: somethingsomethingrandomrecret
default_redirection_url: https://{{ host }}
authentication_backend:
disable_reset_password: true
file:
path: /config/users_database.yml
password:
algorithm: sha512
iterations: 50000
access_control:
default_policy: deny
rules:
- domain:
- {{ host }}
- "*.{{ host }}"
policy: two_factor
session:
name: authelia_session
secret: somerandomsecret
expiration: 1h
inactivity: 5m
remember_me_duration: 1M
domain: {{ host }}
regulation:
max_retries: 3
find_time: 2m
ban_time: 5m
totp:
issuer: authelia.com
storage:
local:
path: /config/db.sqlite3
notifier:
disable_startup_check: false
smtp:
username: {{ email }}
password: {{ email_password }}
host: {{ email_smtp_host }}
port: {{ email_smtp_port_startls }}
sender: {{ email }}
subject: "[Authelia] {title}"
startup_check_address: [email protected]
8 changes: 8 additions & 0 deletions roles/containers/authelia/templates/users_database.yml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
users:
{{ username }}:
displayname: "{{ username }}"
password: "{{ authelia_password | password_hash('sha512') }}"
email: {{ email }}
groups:
- admins
- dev
6 changes: 5 additions & 1 deletion roles/containers/bitwarden/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
---
container_name: vaultwarden
container_name: vaultwarden

homer_url: "https://bitwarden.{{ host }}"

homer_category: services
8 changes: 7 additions & 1 deletion roles/containers/deconz/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
---
container_name: deconz
container_name: deconz

homer_url: "http://{{ ansible_host }}:8085"

homer_category: smarthome

homer_name: "Phoscon-GW"
6 changes: 5 additions & 1 deletion roles/containers/deluge/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
---
container_name: deluge
container_name: deluge

homer_url: "http://{{ ansible_host }}:8112"

homer_category: media
1 change: 0 additions & 1 deletion roles/containers/deluge/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
ports:
- "0.0.0.0:8112:8112"
- "58846:58846"
- "0.0.0.0:8118:8118"
volumes:
- "{{ docker_dir }}/{{ container_name }}/data:/data"
- "{{ docker_dir }}/{{ container_name }}/config:/config"
Expand Down
2 changes: 0 additions & 2 deletions roles/containers/home-assistant/defaults/main.yml

This file was deleted.

10 changes: 10 additions & 0 deletions roles/containers/homeassistant/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
container_name: home-assistant

port: "8123"

homer_url: "http://{{ ansible_host }}:8123"

homer_category: smarthome

homer_name: "Home Assistant"
4 changes: 3 additions & 1 deletion roles/containers/homer/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
---
container_name: homer
container_name: homer
homer_title: "Secret 5G Corona Test Site"
homer_subtitle: "Welcome to my"
14 changes: 14 additions & 0 deletions roles/containers/homer/files/custom.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@charset "UTF-8";
@import url('https://fonts.googleapis.com/css2?family=Fira+Sans:wght@400;700&display=swap');

body, h1, h2, p, .title {
font-family: Fira Sans !important;
font-weight: 400 !important;
}

nav {
display: none !important;
}
body #bighead .first-line .logo img {
border-radius: 50%;
}
Binary file added roles/containers/homer/files/icons/bitwarden.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added roles/containers/homer/files/icons/deconz.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added roles/containers/homer/files/icons/deluge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added roles/containers/homer/files/icons/docker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added roles/containers/homer/files/icons/grafana.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added roles/containers/homer/files/icons/jackett.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added roles/containers/homer/files/icons/jellyfin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added roles/containers/homer/files/icons/logo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added roles/containers/homer/files/icons/nextcloud.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added roles/containers/homer/files/icons/photoprism.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added roles/containers/homer/files/icons/pikvm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added roles/containers/homer/files/icons/radarr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added roles/containers/homer/files/icons/sonarr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added roles/containers/homer/files/icons/syncthing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added roles/containers/homer/files/icons/unifi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added roles/containers/homer/files/icons/wireguard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 62 additions & 1 deletion roles/containers/homer/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,69 @@
---
- name: Get a list of containers
delegate_to: localhost
become: no
find:
paths:
- "roles/containers"
file_type: directory
excludes: "homer"
recurse: no
register: containers

- name: Include all default.yml files
include_vars:
dir: "{{ playbook_dir }}/{{ item.path }}/defaults"
files_matching: main.yml
name: "{{ item.path.split('/')[-1] }}"
with_items: "{{ containers.files }}"
no_log: true

- name: Populate the dictionary of all containers
set_fact:
homer_urls: "{{ homer_urls | default([]) + [{ 'logo': '/assets/tools/homer-icons/' + item.path.split('/')[-1] + '.png', 'name': lookup('vars', item.path.split('/')[-1])['homer_name'] | default(item.path.split('/')[-1] | title), 'url' : lookup('vars', item.path.split('/')[-1])['homer_url'] | default(''), 'category': lookup('vars', item.path.split('/')[-1])['homer_category'] | default ('') }] }}"
when: lookup('vars', 'enable_' + item.path.split('/')[-1]) | default(False)
with_items: "{{ containers.files }}"

- name: Create the icons folder
file:
path: "{{ docker_dir }}/{{ container_name }}/tools/homer-icons"
state: directory

- name: Copy the icons
copy:
src: "files/icons/{{ item.path.split('/')[-1] }}.png"
dest: "{{ docker_dir }}/{{ container_name}}/tools/homer-icons"
owner: "{{ username }}"
group: "{{ username }}"
when: lookup('vars', 'enable_' + item.path.split('/')[-1]) | default(False) and lookup('vars', item.path.split('/')[-1])['homer_url'] is defined
with_items: "{{ containers.files }}"

- name: Copy the logo
copy:
src: "files/icons/logo.jpg"
dest: "{{ docker_dir }}/{{ container_name}}/tools/homer-icons"
owner: "{{ username }}"
group: "{{ username }}"

- name: Copy the custom stylesheet
copy:
src: "files/custom.css"
dest: "{{ docker_dir }}/{{ container_name }}"
owner: "{{ username }}"
group: "{{ username }}"


- name: Generate the Homer config file
template:
src: config.yml.j2
dest: "{{ docker_dir }}/{{ container_name}}/config.yml"
owner: "{{ username }}"
group: "{{ username }}"

- name: Make sure the Homer container is created and running
docker_container:
name: 'homer'
image: "b4bz/homer:latest"
image: "b4bz/homer"
pull: true
state: 'started'
ports:
Expand Down
Loading

0 comments on commit b584cd1

Please sign in to comment.