Skip to content

Commit

Permalink
Sandbox Teslamate (#393)
Browse files Browse the repository at this point in the history
* Updated sandbox.yml and added zurg_testing

* creation of the teslamate role for sandbox

* removed zurg-testing and created teslamate in sandbox.yml

* Update main.yml

added encryption key references in settings and docker env

* Update main.yml

added task to create secret fact for docker encryption.

* Update main.yml

disabled check origin until i can work through the logic of using var's to reference. Currently, check origin is broken.

* Update sandbox.yml

removed reference to mosquitto in sandbox.yml

* Update main.yml

changed upper to lower case, modified database pass to use secrets, set up custom database instead of generic, added traefik default auth page to front end.

* Update main.yml

added creation of new postgres dedicated to teslamate and updated database creation. changed env password over to saltbox facts.

* Update main.yml

fixed formatting in docker exec command for database creation

* Update main.yml

disabled api in trafik config

* Teslamate: Fixups

* Update main.yml

Removed loop on Postgres name

* Update main.yml

Fixed teslamate misspelling in Postgres name

* teslamate: fix postgres version and ENVs

---------

Co-authored-by: owine <[email protected]>
Co-authored-by: saltydk <[email protected]>
  • Loading branch information
3 people authored Oct 22, 2024
1 parent 0ed6b1c commit 635edb4
Show file tree
Hide file tree
Showing 3 changed files with 224 additions and 0 deletions.
163 changes: 163 additions & 0 deletions roles/teslamate/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
#########################################################################
# Title: Sandbox: teslamate #
# Author(s): maindust #
# URL: https://github.com/saltyorg/Sandbox #
# -- #
#########################################################################
# GNU General Public License v3.0 #
#########################################################################
---
# defaults/main.yml

teslamate_name: teslamate

################################
# Settings
################################

teslamate_secret_key: "{{ teslamate_saltbox_facts.facts.secret_key }}"

teslamate_postgres_name: "{{ teslamate_name }}-postgres"
teslamate_postgres_docker_env_db: "{{ teslamate_name }}"
teslamate_postgres_docker_env_password: "{{ teslamate_db_saltbox_facts.facts.secret_key }}"
teslamate_postgres_docker_image_tag: "16"
teslamate_postgres_docker_image_repo: "postgres"
teslamate_postgres_paths_folder: "{{ teslamate_name }}"
teslamate_postgres_paths_location: "{{ server_appdata_path }}/{{ postgres_paths_folder }}/postgres"

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

teslamate_paths_folder: "{{ teslamate_name }}"
teslamate_paths_location: "{{ server_appdata_path }}/{{ teslamate_paths_folder }}"
teslamate_paths_folders_list:
- "{{ teslamate_paths_location }}"

################################
# Web
################################

teslamate_web_subdomain: "{{ teslamate_name }}"
teslamate_web_domain: "{{ user.domain }}"
teslamate_web_port: "4000"
teslamate_web_url: "{{ 'https://' + (teslamate_web_subdomain + '.' + teslamate_web_domain
if (teslamate_web_subdomain | length > 0)
else teslamate_web_domain) }}"

################################
# DNS
################################

teslamate_dns_record: "{{ teslamate_web_subdomain }}"
teslamate_dns_zone: "{{ teslamate_web_domain }}"
teslamate_dns_proxy: "{{ dns.proxied }}"

################################
# Traefik
################################

teslamate_traefik_sso_middleware: "{{ traefik_default_sso_middleware }}"
teslamate_traefik_middleware_default: "{{ traefik_default_middleware }}"
teslamate_traefik_middleware_custom: ""
teslamate_traefik_certresolver: "{{ traefik_default_certresolver }}"
teslamate_traefik_enabled: true
teslamate_traefik_api_enabled: false
teslamate_traefik_api_endpoint: ""

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

# Container
teslamate_docker_container: "{{ teslamate_name }}"

# Image
teslamate_docker_image_pull: true
teslamate_docker_image_tag: "latest"
teslamate_docker_image: "teslamate/teslamate:{{ teslamate_docker_image_tag }}"

# Ports
teslamate_docker_ports_defaults: []
teslamate_docker_ports_custom: []
teslamate_docker_ports: "{{ teslamate_docker_ports_defaults
+ teslamate_docker_ports_custom }}"

# Envs
teslamate_docker_envs_default:
DATABASE_USER: "{{ postgres_docker_env_user }}"
DATABASE_PASS: "{{ teslamate_postgres_docker_env_password }}"
DATABASE_NAME: "{{ teslamate_postgres_docker_env_db }}"
ENCRYPTION_KEY: "{{ teslamate_secret_key }}"
DATABASE_HOST: "{{ teslamate_postgres_name }}"
DATABASE_PORT: "5432"
MQTT_HOST: "mqtt"
CHECK_ORIGIN: "false"
PUID: "{{ uid }}"
PGID: "{{ gid }}"
TZ: "{{ tz }}"
teslamate_docker_envs_custom: {}
teslamate_docker_envs: "{{ teslamate_docker_envs_default
| combine(teslamate_docker_envs_custom) }}"

# Commands
teslamate_docker_commands_default: []
teslamate_docker_commands_custom: []
teslamate_docker_commands: "{{ teslamate_docker_commands_default
+ teslamate_docker_commands_custom }}"

# Volumes
teslamate_docker_volumes_default:
- "{{ teslamate_paths_location }}:/opt/app/import"
teslamate_docker_volumes_custom: []
teslamate_docker_volumes: "{{ teslamate_docker_volumes_default
+ teslamate_docker_volumes_custom }}"

# Devices
teslamate_docker_devices_default: []
teslamate_docker_devices_custom: []
teslamate_docker_devices: "{{ teslamate_docker_devices_default
+ teslamate_docker_devices_custom }}"

# Hosts
teslamate_docker_hosts_default: {}
teslamate_docker_hosts_custom: {}
teslamate_docker_hosts: "{{ docker_hosts_common
| combine(teslamate_docker_hosts_default)
| combine(teslamate_docker_hosts_custom) }}"

# Labels
teslamate_docker_labels_default: {}
teslamate_docker_labels_custom: {}
teslamate_docker_labels: "{{ docker_labels_common
| combine(teslamate_docker_labels_default)
| combine(teslamate_docker_labels_custom) }}"

# Hostname
teslamate_docker_hostname: "{{ teslamate_name }}"

# Networks
teslamate_docker_networks_alias: "{{ teslamate_name }}"
teslamate_docker_networks_default: []
teslamate_docker_networks_custom: []
teslamate_docker_networks: "{{ docker_networks_common
+ teslamate_docker_networks_default
+ teslamate_docker_networks_custom }}"

# Capabilities
teslamate_docker_capabilities_default: []
teslamate_docker_capabilities_custom: []
teslamate_docker_capabilities: "{{ teslamate_docker_capabilities_default
+ teslamate_docker_capabilities_custom }}"

# Security Opts
teslamate_docker_security_opts_default: []
teslamate_docker_security_opts_custom: []
teslamate_docker_security_opts: "{{ teslamate_docker_security_opts_default
+ teslamate_docker_security_opts_custom }}"

# Restart Policy
teslamate_docker_restart_policy: unless-stopped

# State
teslamate_docker_state: started
60 changes: 60 additions & 0 deletions roles/teslamate/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
##########################################################################
# Title: Sandbox: teslamate #
# Author(s): maindust #
# URL: https://github.com/saltyorg/Sandbox #
# -- #
##########################################################################
# GNU General Public License v3.0 #
##########################################################################
---
- name: Add DNS record
ansible.builtin.include_tasks: "{{ resources_tasks_path }}/dns/tasker.yml"
vars:
dns_record: "{{ lookup('vars', role_name + '_dns_record') }}"
dns_zone: "{{ lookup('vars', role_name + '_dns_zone') }}"
dns_proxy: "{{ lookup('vars', role_name + '_dns_proxy') }}"

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

- name: "Save Teslamate Postgres Saltbox facts"
saltbox_facts:
role: "teslamate_db"
instance: "teslamate"
keys:
secret_key: "{{ lookup('ansible.builtin.password', '/dev/null', chars=['ascii_letters', 'digits'], length=50) }}"
owner: "{{ user.name }}"
group: "{{ user.name }}"
register: teslamate_db_saltbox_facts

- name: "Save Teslamate Saltbox facts"
saltbox_facts:
role: "teslamate"
instance: "teslamate"
keys:
secret_key: "{{ lookup('ansible.builtin.password', '/dev/null', chars=['ascii_letters', 'digits'], length=50) }}"
owner: "{{ user.name }}"
group: "{{ user.name }}"
register: teslamate_saltbox_facts

- name: Postgres Role
ansible.builtin.include_role:
name: postgres
vars:
postgres_instances: ["{{ teslamate_postgres_name }}"]
postgres_paths_folder: "{{ teslamate_postgres_paths_folder }}"
postgres_paths_location: "{{ teslamate_postgres_paths_location }}"
postgres_docker_image_repo: "{{ teslamate_postgres_docker_image_repo }}"
postgres_docker_image_tag: "{{ teslamate_postgres_docker_image_tag }}"
postgres_docker_env_db: "{{ teslamate_postgres_docker_env_db }}"
postgres_docker_env_password: "{{ teslamate_postgres_docker_env_password }}"

- name: Mosquitto Role
ansible.builtin.include_role:
name: mqtt

- 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"
1 change: 1 addition & 0 deletions sandbox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
- { role: tdarr_node, tags: ['tdarr-node'] }
- { role: teamspeak, tags: ['teamspeak'] }
- { role: telegraf, tags: ['telegraf'] }
- { role: teslamate, tags: ['teslamate'] }
- { role: thelounge, tags: ['thelounge'] }
- { role: threadfin, tags: ['threadfin'] }
- { role: tika, tags: ['tika'] }
Expand Down

0 comments on commit 635edb4

Please sign in to comment.