Spread services across multiple groups

This commit is contained in:
gabriel becker 2025-08-16 18:57:09 +10:00
parent e4b0ed2fc2
commit 2355aa6e12
19 changed files with 130 additions and 34 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
.venv
.vscode
.vault_pass

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "services"]
path = services
url = https://git.lgoon.xyz/gabriel/lgoon-services

View File

@ -6,13 +6,20 @@ This playbook was tested against a debian 12 image.
## Usage
```bash
ansible-playbook run.yml
ansible-playbook run.yml --ask-pass --ask-become-pass
ansible-playbook run.yml --vault-password-file .vault_pass
```
## Variables
Should be defined in `group_vars/server/vars.yml`:
- **services_dir**: fodler path containing all folders with docker-compose stacks. they should have the scructure `<service>/docker-compose.yml` and optionally include `<service>/.env` files
- **services_dir**: folder path containing all folders with docker-compose stacks. they should have the scructure `<service>/docker-compose.yml` and optionally include `<service>/.env` files
- **services**: list of services in the service_dir container all `<service>` folders
- **packages**: utils packages for linxu environment
## Secrets
```bash
ansible-vault create secret.yml
ansible-vault edit secret
ansible-vault view secret
ansible-vault encrypt secret.yml
```

8
group_vars/all.yml Normal file
View File

@ -0,0 +1,8 @@
packages:
- git
- htop
- rsync
- wget
base_services:
- portainer
services_configs_dir: ""

View File

@ -0,0 +1,3 @@
services:
- gitea
services: "{{ base_services + services }}"

View File

@ -0,0 +1,5 @@
services:
- nextcloud
- syncthing
- immich
services: "{{ base_services + services }}"

View File

@ -0,0 +1,9 @@
services:
# - pinry
# - piped
# - immich
# - monica
# - piwigo
# - vikunja
- syncthing
services: "{{ base_services + services }}"

View File

@ -0,0 +1,9 @@
services:
# - pinry
# - piped
# - immich
# - monica
# - piwigo
# - vikunja
- syncthing
services: "{{ base_services + services }}"

View File

@ -0,0 +1,9 @@
services:
# - pinry
# - piped
# - immich
# - monica
# - piwigo
# - vikunja
- syncthing
services: "{{ base_services + services }}"

View File

@ -1,10 +1,9 @@
packages:
- git
- htop
services:
- pinry
- immich
- monica
- piwigo
- vikunja
services_dir: /home/gabriel/hosted
# - pinry
# - piped
# - immich
# - monica
# - piwigo
# - vikunja
- syncthing

View File

@ -0,0 +1,9 @@
services:
# - pinry
# - piped
# - immich
# - monica
# - piwigo
# - vikunja
- syncthing
services: "{{ global_services + services }}"

View File

@ -1,8 +1,22 @@
server:
file-servers:
hosts:
ec2-13-239-10-136.ap-southeast-2.compute.amazonaws.com:
debianpx:
ansible_host: 192.168.122.177
ansible_user: gabriel
vars:
ansible_user: admin
ansible_ssh_private_key_file: /home/gabriel/dev/terraform/terraform-lab/ec2ml/my_ssh.pem
PERSISTENT_DIRECTORY: /persistent
VOLATILE_DIRECTORY: /volatile %
services_dir: /home/gabriel/hosted
services_configs_dir: /home/gabriel/hosted/configs
PERSISTENT_DIRECTORY: /home/gabriel/hosted/persistent
VOLATILE_DIRECTORY: /home/gabriel/hosted/volatile
BACKUPDIR: /home/gabriel/hosted/backup
APPSDIR: /home/gabriel/hosted/apps
MEDIADIR: /home/gabriel/hosted/media
media-servers:
hosts:
algrroca:
ansible_user: root
# ansible_ssh_private_key_file: /home/gabriel/.ssh/aws_ec2_ssh.pem
# PERSISTENT_DIRECTORY: /home/srv/raidded
# VOLATILE_DIRECTORY: /home/srv/mstorage
# ansible_sudo_pass:

1
requirments.txt Normal file
View File

@ -0,0 +1 @@
ansible

View File

@ -1,10 +1,10 @@
---
- name: Update packages
apt:
update_cache: yes
upgrade: yes
ansible.builtin.apt:
update_cache: true
upgrade: true
- name: Install essential packages
package:
ansible.builtin.package:
name: "{{ packages }}"
state: latest

View File

@ -1,12 +1,12 @@
---
- name: Install aptitude
apt:
ansible.builtin.apt:
name: aptitude
state: latest
update_cache: true
- name: Install required system packages
apt:
ansible.builtin.apt:
pkg:
- apt-transport-https
- ca-certificates
@ -19,23 +19,23 @@
update_cache: true
- name: Add Docker GPG apt Key
apt_key:
ansible.builtin.apt_key:
url: https://download.docker.com/linux/debian/gpg
state: present
- name: Add Docker Repository
apt_repository:
ansible.builtin.apt_repository:
repo: deb https://download.docker.com/linux/debian bookworm stable
state: present
- name: Update apt and install docker-ce
apt:
ansible.builtin.apt:
name: docker-ce
state: latest
update_cache: true
- name: Update apt and install docker-compose
apt:
ansible.builtin.apt:
name: docker-compose
state: latest
update_cache: true
@ -44,3 +44,9 @@
ansible.builtin.pip:
name: docker
extra_args: --break-system-packages
- name: adding existing user to group docker '{{ ansible_user }}'
ansible.builtin.user:
name: '{{ ansible_user }}'
groups: docker
append: true

View File

@ -1,5 +1,5 @@
---
- include_tasks: dependencies.yml
- include_tasks: install_docker.yml
- include_tasks: start_service.yml
- include_tasks: nginx_config.yml
- ansible.builtin.include_tasks: dependencies.yml
- ansible.builtin.include_tasks: install_docker.yml
- ansible.builtin.include_tasks: start_service.yml
- ansible.builtin.include_tasks: nginx_config.yml

View File

@ -1,6 +1,6 @@
---
- name: Copy service folder
copy:
ansible.builtin.copy:
src: "{{ services_dir }}/nginx-npm"
dest: /services/

View File

@ -8,4 +8,5 @@
- name: Start Docker compose
community.docker.docker_compose:
project_src: "/services/{{ item }}"
environment: "{{ compose_env }}"
with_items: "{{ services }}"

14
run.yml
View File

@ -1,5 +1,17 @@
---
- hosts: server
become: yes
become: true
roles:
- role: webserver
# vars_files:
# - secret
- hosts: file-servers
become: true
roles:
- role: webserver
- hosts: media-servers
become: true
roles:
- role: webserver