Skip to content

Commit

Permalink
Unifi-Network-Application: New Role
Browse files Browse the repository at this point in the history
  • Loading branch information
owine committed Nov 26, 2023
1 parent b96cb34 commit eb1e4f8
Show file tree
Hide file tree
Showing 4 changed files with 212 additions and 0 deletions.
163 changes: 163 additions & 0 deletions roles/unifi-network-application/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
############################################################################
# Title: Sandbox: Unifi Network Application | Default Variables #
# Author(s): Grostim, owine #
# URL: https://github.com/saltyorg/Sandbox #
# -- #
############################################################################
# GNU General Public License v3.0 #
############################################################################
---
################################
# Basics
################################

unifi_network_application_name: unifi

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

unifi_network_application_mongo_user: "unifi"
unifi_network_application_mongo_pass: "password4321"
unifi_network_application_mongo_port: "27017"
unifi_network_application_mongo_dbname: "unifi"

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

unifi_network_application_paths_folder: "{{ unifi_network_application_name }}"
unifi_network_application_paths_location: "{{ server_appdata_path }}/{{ unifi_network_application_paths_folder }}"
unifi_network_application_paths_folders_list:
- "{{ unifi_network_application_paths_location }}"

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

unifi_network_application_web_subdomain: "{{ unifi_network_application_name }}"
unifi_network_application_web_domain: "{{ user.domain }}"
unifi_network_application_web_port: "8443"
unifi_network_application_web_scheme: "https"
unifi_network_application_web_serverstransport: "skipverify@file"
unifi_network_application_web_url: "{{ 'https://' + (unifi_network_application_web_subdomain + '.' + unifi_network_application_web_domain
if (unifi_network_application_web_subdomain | length > 0)
else unifi_network_application_web_domain) }}"

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

unifi_network_application_dns_record: "{{ unifi_network_application_web_subdomain }}"
unifi_network_application_dns_zone: "{{ unifi_network_application_web_domain }}"
unifi_network_application_dns_proxy: "{{ dns.proxied }}"

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

unifi_network_application_traefik_sso_middleware: ""
unifi_network_application_traefik_middleware_default: "{{ traefik_default_middleware }}"
unifi_network_application_traefik_middleware_custom: ""
unifi_network_application_traefik_certresolver: "{{ traefik_default_certresolver }}"
unifi_network_application_traefik_enabled: true
unifi_network_application_traefik_api_enabled: false
unifi_network_application_traefik_api_endpoint: ""

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

# Container
unifi_network_application_docker_container: "{{ unifi_network_application_name }}"

# Image
unifi_network_application_docker_image_pull: true
unifi_network_application_docker_image_tag: "latest"
unifi_network_application_docker_image_repo: "lscr.io/linuxserver/unifi-network-application"
unifi_network_application_docker_image: "{{ unifi_network_application_docker_image_repo }}:{{ unifi_network_application_docker_image_tag }}"

# Ports
unifi_network_application_docker_ports_defaults:
- "8080:8080/tcp"
- "3478:3478/udp"
- "10001:10001/udp"
unifi_network_application_docker_ports_custom: []
unifi_network_application_docker_ports: "{{ unifi_network_application_docker_ports_defaults
+ unifi_network_application_docker_ports_custom }}"

# Envs
unifi_network_application_docker_envs_default:
PUID: "{{ uid }}"
PGID: "{{ gid }}"
TZ: "{{ tz }}"
MONGO_USER: "{{ unifi_network_application_mongo_user }}"
MONGO_PASS: "{{ unifi_network_application_mongo_pass }}"
MONGO_HOST: "{{ unifi_network_application_name }}_mongo"
MONGO_PORT: "{{ unifi_network_application_mongo_port }}"
MONGO_DBNAME: "{{ unifi_network_application_mongo_dbname }}"
unifi_network_application_docker_envs_custom: {}
unifi_network_application_docker_envs: "{{ unifi_network_application_docker_envs_default
| combine(unifi_network_application_docker_envs_custom) }}"

# Commands
unifi_network_application_docker_commands_default: []
unifi_network_application_docker_commands_custom: []
unifi_network_application_docker_commands: "{{ unifi_network_application_docker_commands_default
+ unifi_network_application_docker_commands_custom }}"

# Volumes
unifi_network_application_docker_volumes_default:
- "{{ unifi_network_application_paths_location }}:/config"
unifi_network_application_docker_volumes_custom: []
unifi_network_application_docker_volumes: "{{ unifi_network_application_docker_volumes_default
+ unifi_network_application_docker_volumes_custom }}"

# Devices
unifi_network_application_docker_devices_default: []
unifi_network_application_docker_devices_custom: []
unifi_network_application_docker_devices: "{{ unifi_network_application_docker_devices_default
+ unifi_network_application_docker_devices_custom }}"

# Hosts
unifi_network_application_docker_hosts_default: []
unifi_network_application_docker_hosts_custom: []
unifi_network_application_docker_hosts: "{{ docker_hosts_common
| combine(unifi_network_application_docker_hosts_default)
| combine(unifi_network_application_docker_hosts_custom) }}"

# Labels
unifi_network_application_docker_labels_default: {}
unifi_network_application_docker_labels_custom: {}
unifi_network_application_docker_labels: "{{ docker_labels_common
| combine(unifi_network_application_docker_labels_default)
| combine(unifi_network_application_docker_labels_custom) }}"

# Hostname
unifi_network_application_docker_hostname: "{{ unifi_network_application_name }}"

# Networks
unifi_network_application_docker_networks_alias: "{{ unifi_network_application_name }}"
unifi_network_application_docker_networks_default: []
unifi_network_application_docker_networks_custom: []
unifi_network_application_docker_networks: "{{ docker_networks_common
+ unifi_network_application_docker_networks_default
+ unifi_network_application_docker_networks_custom }}"

# Capabilities
unifi_network_application_docker_capabilities_default: []
unifi_network_application_docker_capabilities_custom: []
unifi_network_application_docker_capabilities: "{{ unifi_network_application_docker_capabilities_default
+ unifi_network_application_docker_capabilities_custom }}"

# Security Opts
unifi_network_application_docker_security_opts_default: []
unifi_network_application_docker_security_opts_custom: []
unifi_network_application_docker_security_opts: "{{ unifi_network_application_docker_security_opts_default
+ unifi_network_application_docker_security_opts_custom }}"

# Restart Policy
unifi_network_application_docker_restart_policy: unless-stopped

# State
unifi_network_application_docker_state: started
47 changes: 47 additions & 0 deletions roles/unifi-network-application/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#########################################################################
# Title: Sandbox: Unifi Network Application #
# Author(s): Grostim, owine #
# 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 legacy Unifi container
ansible.builtin.include_tasks: "{{ resources_tasks_path }}/docker/remove_docker_container.yml"
vars:
_var_prefix: "unifi"

- 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: "Unifi | Import init-mongo.js"
ansible.builtin.template:
src: init-mongo.js.j2
dest: '{{ unifi_network_application_paths_location }}/init-mongo.js'
owner: "{{ user.name }}"
group: "{{ user.name }}"
mode: "0775"
force: yes

- name: MongoDB Role
ansible.builtin.include_role:
name: mongodb
vars:
mongodb_instances: ["{{ unifi_network_application_name }}_mongo"]
mongodb_paths_location: "{{ server_appdata_path }}/{{ unifi_network_application_name }}"
mongodb_docker_image_tag: "4.4"
mongodb_docker_volumes_custom: ["{{ unifi_network_application_paths_location }}/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro"]

- name: Create Docker container
ansible.builtin.include_tasks: "{{ resources_tasks_path }}/docker/create_docker_container.yml"
1 change: 1 addition & 0 deletions roles/unifi-network-application/templates/init-mongo.js.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
db.getSiblingDB("{{ unifi_network_application_mongo_dbname }}").createUser({user: "{{ unifi_network_application_mongo_user }}", pwd: "{{ unifi_network_application_mongo_pass }}", roles: [{role: "dbOwner", db: "{{ unifi_network_application_mongo_dbname }}"}, {role: "dbOwner", db: "{{ unifi_network_application_mongo_dbname }}_stat"}]});
1 change: 1 addition & 0 deletions sandbox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
- { role: tubearchivist, tags: ['tubearchivist'] }
- { role: tvheadend, tags: ['tvheadend'] }
- { role: unifi, tags: ['unifi'] }
- { role: unifi-network-application, tags: ['unifi-network-application'] }
- { role: unmanic, tags: ['unmanic'] }
- { role: uptime_kuma, tags: ['uptime-kuma'] }
- { role: varken, tags: ['varken'] }
Expand Down

0 comments on commit eb1e4f8

Please sign in to comment.