commit dc401dc6f239446855ddfe5213772ff32586a4d8 Author: Mike Holloway Date: Sun Aug 2 00:58:04 2026 -0400 Initial commit - working. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..4248488 --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +Copyright 2024 Equilibrate IT Inc. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..9a67a90 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for podman_ollama diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..ee8bd25 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for podman_ollama diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..3f2ec16 --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,28 @@ +--- +dependencies: [] + +galaxy_info: + role_name: podman_ollama + author: "Mike Holloway" + description: "Installs and configures ollama + open-webui." + company: "Equilibrate IT Inc." + license: "license (BSD-2-Clause)" + min_ansible_version: 2.10 + platforms: + - name: Fedora + versions: + - all + - name: Ubuntu + versions: + - all + - name: Debian + versions: + - all + galaxy_tags: + - networking + - system + - podman + - container + - ollama + - llm + - open-webui diff --git a/tasks/certificates.yml b/tasks/certificates.yml new file mode 100644 index 0000000..31f5703 --- /dev/null +++ b/tasks/certificates.yml @@ -0,0 +1,17 @@ +- name: Check for certs + file: + path: "/home/{{ user.name }}/proxy/certs/{{ item }}" + state: file + loop: + - "{{ inventory_hostname }}.key" + - "{{ inventory_hostname }}.crt" + ignore_errors: true + register: iscert + +- debug: msg="{{ iscert.msg }}" + +- import_tasks: certificates_self.yml + when: "'self' in certificates and 'failed' in iscert.msg" + +- import_tasks: certificates_certbot.yml + when: "'certbot' in certificates and 'failed' in iscert.msg" diff --git a/tasks/certificates_certbot.yml b/tasks/certificates_certbot.yml new file mode 100644 index 0000000..ebbd15d --- /dev/null +++ b/tasks/certificates_certbot.yml @@ -0,0 +1,14 @@ +- name: Create certbot certs + copy: + remote_src: true + src: "/etc/letsencrypt/live/{{ inventory_hostname }}/privkey.pem" + dest: "/home/{{ user.name }}/proxy/certs/{{ inventory_hostname }}.key" + owner: 100033 + group: 100033 + +- copy: + remote_src: true + src: "/etc/letsencrypt/live/{{ inventory_hostname }}/fullchain.pem" + dest: "/home/{{ user.name }}/proxy/certs/{{ inventory_hostname }}.crt" + owner: 100033 + group: 100033 diff --git a/tasks/certificates_self.yml b/tasks/certificates_self.yml new file mode 100644 index 0000000..7ad1e60 --- /dev/null +++ b/tasks/certificates_self.yml @@ -0,0 +1,60 @@ +- name: Create self-signed certs + become: yes + become_user: nextcloud + command: + chdir: /home/{{ user.name }}/ + creates: "/home/{{ user.name }}/{{ inventory_hostname }}.key" + argv: + - openssl + - req + - -x509 + - -newkey + - rsa:4096 + - -sha256 + - -nodes + - -keyout + - "{{ inventory_hostname }}.key" + - -out + - "{{ inventory_hostname }}.crt" + - -days + - 3650 + - -subj + - "/C=CA/ST=ON/L=Toronto/O=EquilibrateIT/OU=SecretManagement/CN={{ inventory_hostname}}" + - -addext + - "subjectAltName = DNS:{{ inventory_hostname }},DNS:localhost,IP:127.0.0.1" + + #- name: Add certificate trust + # become: yes + # become_user: nextcloud + # command: + # chdir: /home/nextcloud/ + # creates: "/home/nextcloud/{{ inventory_hostname }}.crt" + # argv: + # - openssl + # - x509 + # - -trustout + # - -in + # - "{{ inventory_hostname}}.normal.crt" + # - -out + # - "{{ inventory_hostname}}.crt" + + +- copy: + src: "/home/{{ user.name }}/{{ inventory_hostname }}.crt" + remote_src: true + dest: /home/{{ user.name }}/proxy/certs/ + owner: 100033 + +- copy: + src: "/home/{{ user.name }}/{{ inventory_hostname }}.key" + remote_src: true + dest: /home/{{ user.name }}/proxy/certs/ + owner: 100033 + +- file: + path: "/home/nextcloud/{{ item }}" + state: absent + with_items: + - "{{ inventory_hostname }}.normal.crt" + - "{{ inventory_hostname }}.crt" + - "{{ inventory_hostname }}.key" diff --git a/tasks/files.yml b/tasks/files.yml new file mode 100644 index 0000000..d536420 --- /dev/null +++ b/tasks/files.yml @@ -0,0 +1,19 @@ +- name: Container directory paths + file: + path: "/home/{{ user.name }}/{{ subdir }}" + state: directory + owner: "{{ user.name }}" + group: "{{ user.name }}" + with_items: + - ".ollama" + - "open-webui/data" + loop_control: + loop_var: "subdir" + + +- name: Create Compose File + template: + src: "docker-compose.yml.j2" + dest: "/home/{{ user.name }}/docker-compose.yml" + owner: "{{ user.name }}" + group: "{{ user.name }}" diff --git a/tasks/firewall.yml b/tasks/firewall.yml new file mode 100644 index 0000000..a8a6a54 --- /dev/null +++ b/tasks/firewall.yml @@ -0,0 +1,33 @@ +- name: Root port openings and forwards for web traffic. + firewalld: + port: "{{ item }}" + zone: public + permanent: true + immediate: true + state: enabled + with_items: + - "80/tcp" + - "443/tcp" + +- name: Root port openings and forwards for local traffic + firewalld: + port: "{{ item }}" + zone: trusted + permanent: true + immediate: true + state: enabled + with_items: + - "11434/tcp" + +- firewalld: + rich_rule: "{{ item }}" + zone: public + permanent: true + immediate: true + state: enabled + with_items: + - "rule family=ipv4 forward-port port=80 protocol=tcp to-port=8080" + - "rule family=ipv4 forward-port port=443 protocol=tcp to-port=4443" + +- command: + cmd: "firewall-cmd --reload" diff --git a/tasks/include-vars.yml b/tasks/include-vars.yml new file mode 100644 index 0000000..0a70e50 --- /dev/null +++ b/tasks/include-vars.yml @@ -0,0 +1,8 @@ +--- +- name: Load a variable file based on the OS type, or a default if not found. + include_vars: "{{ item }}" + with_first_found: + - "{{ ansible_distribution }}-{{ ansible_distribution_version }}.yml" + - "{{ ansible_distribution }}.yml" + - "{{ ansible_os_family }}.yml" + - "default.yml" diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..8474a0d --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,30 @@ +--- +# tasks file for podman_ollama +- import_tasks: include-vars.yml + +- name: Parse passwd + getent: + database: passwd + +- block: + #- include_tasks: certificates.yml + # with_items: + # - "{{ service_users }}" + # loop_control: + # loop_var: "user" + - include_tasks: files.yml + with_items: + - "{{ service_users }}" + loop_control: + loop_var: "user" + - include_tasks: firewall.yml + with_items: + - "{{ service_users }}" + loop_control: + loop_var: "user" + - include_tasks: os.yml + with_items: + - "{{ service_users }}" + loop_control: + loop_var: "user" + when: '"ollama" in user.services' diff --git a/tasks/os.yml b/tasks/os.yml new file mode 100644 index 0000000..650116e --- /dev/null +++ b/tasks/os.yml @@ -0,0 +1,29 @@ + +- name: NVIDIA Container Toolkit == Prerequisites + dnf: + name: "curl" + state: present + +- command: | + curl -s -L https://nvidia.github.io/libnvidia-container/stable/rpm/nvidia-container-toolkit.repo --output /etc/yum.repos.d/nvidia-container-toolkit.repo + args: + creates: "/etc/yum.repos.d/nvidia-container-toolkit.repo" + +- vars: + container_toolkit_version: "1.19.1-1" + dnf: + name: "{{ item }}{{ container_toolkit_version}}" + state: present + with_items: + - "nvidia-container-toolkit-" + - "nvidia-container-toolkit-base-" + - "libnvidia-container-tools-" + - "libnvidia-container1-" +- command: | + nvidia-ctk cdi generate --output=/etc/cdi/nvidia.yaml + args: + creates: "/etc/cdi/nvidia.yaml" +- seboolean: + name: container_use_devices + state: true + persistent: true diff --git a/templates/db.env.j2 b/templates/db.env.j2 new file mode 100644 index 0000000..45f321a --- /dev/null +++ b/templates/db.env.j2 @@ -0,0 +1,3 @@ +POSTGRES_PASSWORD= +NEXTCLOUD_ADMIN_USER="admin" +NEXTCLOUD_ADMIN_PASSWORD= diff --git a/templates/docker-compose.yml.j2 b/templates/docker-compose.yml.j2 new file mode 100644 index 0000000..ee73868 --- /dev/null +++ b/templates/docker-compose.yml.j2 @@ -0,0 +1,27 @@ +services: + ollama: + image: ollama:latest + hostname: ollama + restart: always + devices: + - "nvidia.com/gpu=all" + volumes: + - /home/{{ user.name }}/.ollama:/root/.ollama:Z + ports: + - "11434:11434" + environment: + - OLLAMA_CONTEXT_LENGTH={{ ollama_context_length }} + + openwebui: + image: ghcr.io/open-webui/open-webui:main + hostname: openwebui + restart: always + ports: + - "8080:8080" + volumes: + - /home/{{ user.name }}/open-webui:/app/backend/data:Z + environment: + - OLLAMA_BASE_URL=http://ollama:11434 + - ENABLE_FOLDERS=true + depends_on: + - ollama 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..3632d6d --- /dev/null +++ b/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - podman_ollama diff --git a/vars/default.yml b/vars/default.yml new file mode 100644 index 0000000..650da4f --- /dev/null +++ b/vars/default.yml @@ -0,0 +1,3 @@ +--- +certbot_auto_renew_user: "root" +wordpress_site_url: "ansible_default.url" diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..c78d13a --- /dev/null +++ b/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for podman_ollama