From 72b607a11771f0ea0a6fa1c5a967ec44610be436 Mon Sep 17 00:00:00 2001 From: Tim Unkrig Date: Tue, 31 Oct 2023 12:33:59 +0100 Subject: [PATCH] added tasks --- defaults/main.yml | 2 ++ files/docker-compose.yaml.j2 | 39 ++++++++++++++++++++++++++++++ files/init-mongo.js | 2 ++ handlers/main.yml | 2 ++ meta/.galaxy_install_info | 2 ++ meta/main.yml | 47 ++++++++++++++++++++++++++++++++++++ tasks/main.yml | 36 +++++++++++++++++++++++++++ tests/inventory | 2 ++ tests/test.yml | 5 ++++ vars/main.yml | 3 +++ 10 files changed, 140 insertions(+) create mode 100644 defaults/main.yml create mode 100644 files/docker-compose.yaml.j2 create mode 100644 files/init-mongo.js create mode 100644 handlers/main.yml create mode 100644 meta/.galaxy_install_info create mode 100644 meta/main.yml create mode 100644 tasks/main.yml create mode 100644 tests/inventory create mode 100644 tests/test.yml create mode 100644 vars/main.yml diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..93e47ad --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for unifi_controller \ No newline at end of file diff --git a/files/docker-compose.yaml.j2 b/files/docker-compose.yaml.j2 new file mode 100644 index 0000000..d80e5b5 --- /dev/null +++ b/files/docker-compose.yaml.j2 @@ -0,0 +1,39 @@ +--- +version: '3' +services: + unifi-db: + image: docker.io/mongo:4.4 + container_name: unifi-db + environment: + PUID: 1000 + GUID: 1000 + volumes: + - {{ unifi_controller_app_dir }}/mongodb/data:/data/db + - {{ unifi_controller_app_dir }}/mongodb/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro + restart: always + + unifi-network-application: + image: lscr.io/linuxserver/unifi-network-application:latest + container_name: unifi-network-application + environment: + - PUID=1000 + - PGID=1000 + - TZ=Europe/Berlin + - MONGO_USER=unifi + - MONGO_PASS=unifi + - MONGO_HOST=unifi-db + - MONGO_PORT=27017 + - MONGO_DBNAME=unifi + volumes: + - {{ unifi_controller_app_dir }}/data:/config + ports: + - 8443:8443 + - 3478:3478/udp + - 10001:10001/udp + - 8080:8080 + - 1900:1900/udp #optional + - 8843:8843 #optional + - 8880:8880 #optional + - 6789:6789 #optional + - 5514:5514/udp #optional + restart: unless-stopped \ No newline at end of file diff --git a/files/init-mongo.js b/files/init-mongo.js new file mode 100644 index 0000000..a648b70 --- /dev/null +++ b/files/init-mongo.js @@ -0,0 +1,2 @@ +db.getSiblingDB("unifi").createUser({user: "unifi", pwd: "unifi", roles: [{role: "readWrite", db: "unifi"}]}); +db.getSiblingDB("unifi_stat").createUser({user: "unifi", pwd: "unifi", roles: [{role: "readWrite", db: "unifi_stat"}]}); \ No newline at end of file diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..88552b1 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for unifi_controller diff --git a/meta/.galaxy_install_info b/meta/.galaxy_install_info new file mode 100644 index 0000000..797f145 --- /dev/null +++ b/meta/.galaxy_install_info @@ -0,0 +1,2 @@ +install_date: Mon Oct 23 14:05:36 2023 +version: '' diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..c4c064c --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,47 @@ +galaxy_info: + author: Tim Unkrig + description: docker install homelab + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: "2.8" + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + platforms: + - name: Debian + versions: + - "bookworm" + - name: Ubuntu + versions: + - "jammy" + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..ee135ac --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,36 @@ +--- +# tasks file for pi-hole + +- name: Create unifi controller directories + ansible.builtin.file: + path: "{{ item }}" + state: directory + mode: '0755' + loop: + - "{{ unifi_controller_app_dir }}" + - "{{ unifi_controller_app_dir }}/data" + - "{{ unifi_controller_app_dir }}/mongodb" + - "{{ unifi_controller_app_dir }}/mongodb/data/" + +- name: Copy init mongo script + ansible.builtin.copy: + src: "../files/init-mongo.js" + dest: "{{ unifi_controller_app_dir }}/mongodb" + owner: root + group: root + mode: '0755' + +- name: Templating docker-compose.yml + ansible.builtin.template: + src: files/docker-compose.yaml.j2 + dest: "{{ unifi_controller_app_dir }}/docker-compose.yaml" + owner: root + group: root + mode: '0660' + validate: docker-compose config --quiet --file %s + backup: true + +- name: Start docker-compose + community.docker.docker_compose: + project_src: "{{ unifi_controller_app_dir }}" + state: present diff --git a/tests/inventory b/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/tests/test.yml b/tests/test.yml new file mode 100644 index 0000000..fd095ef --- /dev/null +++ b/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - haup.gitea diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..473ebce --- /dev/null +++ b/vars/main.yml @@ -0,0 +1,3 @@ +--- +# vars file for unifi_controller +unifi_controller_app_dir: "/srv/unifi"