From 9e5403f5ea77b2a2583799b27c9318d79e54c19e Mon Sep 17 00:00:00 2001 From: Laur Ivan Date: Wed, 8 Jan 2025 23:42:27 +0100 Subject: [PATCH] fix: Fix errorneous mongo configuration --- defaults/main.yml | 32 +++++++++++----- tasks/config.yml | 31 ++++++++++++---- templates/docker-compose.yml.j2 | 51 ++++++++++++++++++-------- templates/env.unifi-controller.conf.j2 | 11 ++++-- 4 files changed, 89 insertions(+), 36 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index b13c217..9aa9651 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,8 +1,9 @@ --- ## General -unifi_image: lscr.io/linuxserver/unifi-network-application:latest -unifi_container_name: unifi-network-application +unifi_image_unifi: lscr.io/linuxserver/unifi-network-application:latest +unifi_image_mongodb: docker.io/mongo:3.6 +unifi_container_name_unifi: unifi-network-application unifi_uid: 1000 unifi_gid: 1000 @@ -24,28 +25,39 @@ unifi_http_port_8880: 8880 unifi_http_port_6789: 6789 unifi_http_port_5514: 5514 +unifi_server_enabled: true +unifi_mongo_local: true unifi_mongo_user: unifi -unifi_mongo_pass: -unifi_mongo_host: unifi-db +unifi_mongo_pass: unifi +unifi_mongo_host: "unifi-db" unifi_mongo_port: 27017 -unifi_nongo_db_name: unifi -unifi_mongo_auth_source: admin +unifi_mongo_db_name: unifi-db +unifi_mongo_auth_source: unifi_mongo_tls: # Unifi-Controller paths unifi_root_path: /var/local -unifi_data_base: "{{ unifi_root_path }}/unifi-controller" -unifi_config_path: "{{ unifi_root_path }}/conf/unifi-controller" +unifi_config_path: "{{ unifi_root_path }}/conf/unifi-network-application" +unifi_data_base: "{{ unifi_root_path }}/unifi-network-application/unifi" +unifi_mongodb_path: "{{ unifi_data_base }}/unifi-db" +unifi_network_application_path: "{{ unifi_data_base }}/unifi-network-application" + + # Add other paths here to make sure they're created automatically # unifi_skeleton_paths: - "{{ unifi_config_path }}" + - "{{ unifi_data_base }}" + - "{{ unifi_mongodb_path }}" + - "{{ unifi_network_application_path }}" # Add more templates to be copied into the config unifi_configuration_files: - - "docker-compose.yml" - - "env.unifi-controller.conf" + - ["docker-compose.yml", "0640"] + - ["env.unifi-controller.conf", "0640"] + - ["env.mongodb.conf", "0640"] + - ["init-mongo.js", "0644"] # Documentation unifi_documentation_link: "https://www.laurivan.com" diff --git a/tasks/config.yml b/tasks/config.yml index 76b6f1d..ab0a2c5 100644 --- a/tasks/config.yml +++ b/tasks/config.yml @@ -1,22 +1,39 @@ --- -- name: "UNIFI-CONTROLLER | Set up directories" +- name: "UNIFI-CONTROLLER | Check existing directories" + ansible.builtin.stat: + path: "{{ item }}" + register: unifi_folder_stats + with_items: + - "{{ unifi_skeleton_paths }}" + tags: + - unifi_configure + become: true + +- name: "UNIFI-CONTROLLER | Print scanned dirs" + ansible.builtin.debug: + msg: "Scanned: {{ item }}" + loop: "{{ unifi_folder_stats.results | map(attribute='item') | list }}" + +- name: "UNIFI-CONTROLLER | Set up directories if they don't exist" ansible.builtin.file: state: directory - path: "{{ item }}" + path: "{{ item.invocation.module_args.path }}" owner: "{{ ansible_effective_user_id }}" group: "{{ ansible_effective_group_id }}" mode: "0750" - with_items: - - "{{ unifi_skeleton_paths }}" + loop: "{{ unifi_folder_stats.results }}" + loop_control: + label: "{{ item.invocation.module_args.path }}" + when: not item.stat.exists tags: - unifi_configure become: true - name: "UNIFI-CONTROLLER | Write configuration files" ansible.builtin.template: - src: "{{ item }}.j2" - dest: "{{ unifi_config_path | expanduser | realpath }}/{{ item }}" - mode: '0640' + src: "{{ item[0] }}.j2" + dest: "{{ unifi_config_path | expanduser | realpath }}/{{ item[0] }}" + mode: "{{ item[1] }}" with_items: - "{{ unifi_configuration_files }}" tags: diff --git a/templates/docker-compose.yml.j2 b/templates/docker-compose.yml.j2 index 55bc0f3..a8394ac 100644 --- a/templates/docker-compose.yml.j2 +++ b/templates/docker-compose.yml.j2 @@ -1,10 +1,29 @@ -# unifi-controller docker compose +# unifi-network-app docker compose --- -version: '3.9' services: +{% if unifi_mongo_local %} + unifi-db: + container_name: unifi-db + image: "{{ unifi_image_mongodb }}" + env_file: + - "{{ unifi_config_path | expanduser }}/env.mongodb.conf" + ports: + - target: 27017 + published: "27017" + protocol: tcp + restart: unless-stopped + volumes: + - "{{ unifi_config_path | expanduser }}/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js" + - type: bind + source: "{{ unifi_mongodb_path }}" + target: /data/db + networks: + - unifi-bridge +{% endif %} +{% if unifi_server_enabled %} unifi-controller: - image: "{{ unifi_image }}" - container_name: "{{ unifi_container_name }}" + image: "{{ unifi_image_unifi }}" + container_name: "{{ unifi_container_name_unifi }}" restart: unless-stopped env_file: - "{{ unifi_config_path | expanduser }}/env.unifi-controller.conf" @@ -13,29 +32,31 @@ services: - "{{ unifi_http_port_3478 }}:3478/udp" - "{{ unifi_http_port_10001 }}:10001/udp" - "{{ unifi_http_port_8080 }}:8080" - {% if unifi_http_port_1900 is defined -%} + {% if unifi_http_port_1900 is defined and unifi_http_port_1900 -%} - "{{ unifi_http_port_1900 }}:1900/udp" {% endif -%} - {% if unifi_http_port_8843 is defined -%} + {% if unifi_http_port_8843 is defined and unifi_http_port_8843 -%} - "{{ unifi_http_port_8843 }}:8843" {% endif -%} - {% if unifi_http_port_8880 is defined -%} + {% if unifi_http_port_8880 is defined and unifi_http_port_8880 -%} - "{{ unifi_http_port_8880 }}:8880" {% endif -%} - {% if unifi_http_port_6789 is defined -%} + {% if unifi_http_port_6789 is defined and unifi_http_port_6789 -%} - "{{ unifi_http_port_6789 }}:6789" {% endif -%} - {% if unifi_http_port_5514 is defined -%} + {% if unifi_http_port_5514 is defined and unifi_http_port_5514 -%} - "{{ unifi_http_port_5514 }}:5514/udp" {% endif %} networks: - - unifi-controller-net + - unifi-bridge volumes: - - "{{ unifi_volume }}:/config" - -volumes: - {{ unifi_volume }}: + - type: bind + source: "{{ unifi_network_application_path }}" + target: /config +{% endif %} networks: - unifi-controller-net: {} + unifi-bridge: + driver: bridge + diff --git a/templates/env.unifi-controller.conf.j2 b/templates/env.unifi-controller.conf.j2 index 7b9dc9f..b2b5b72 100644 --- a/templates/env.unifi-controller.conf.j2 +++ b/templates/env.unifi-controller.conf.j2 @@ -1,18 +1,21 @@ # Add environment variables for unifi-controller here # Note: This is a .ini file format PUID={{ unifi_uid }} -PUID={{ unifi_gid }} +GUID={{ unifi_gid }} MEM_LIMIT={{ unifi_mem_limit }} MEM_STATUP={{ unifi_mem_startup }} -TZ={{ unifi_tz }} MONGO_USER={{ unifi_mongo_user }} +{% if unifi_mongo_pass is defined and unifi_mongo_pass -%} MONGO_PASS={{ unifi_mongo_pass }} +{% endif %} MONGO_HOST={{ unifi_mongo_host }} MONGO_PORT={{ unifi_mongo_port }} -MONGO_DBNAME={{ unifi_nongo_db_name }} +MONGO_DBNAME={{ unifi_mongo_db_name }} +{% if unifi_mongo_auth_source is defined and unifi_mongo_auth_source -%} MONGO_AUTHSOURCE={{ unifi_mongo_auth_source }} -{% if unifi_mongo_tls is defined -%} +{% endif %} +{% if unifi_mongo_tls is defined and unifi_mongo_tls -%} MONGO_TLS= {{ unifi_mongo_tls }} {% endif %}