Compare commits

..

4 Commits

Author SHA1 Message Date
gabriel becker
a9623b63f1 Make sure we can copy files correctly to destination 2025-08-16 20:52:29 +10:00
gabriel becker
b5af3c9b5d Fix recursion in services variables 2025-08-16 19:25:36 +10:00
gabriel becker
1e7e6b612d Fix install docker for trixie 2025-08-16 18:58:19 +10:00
gabriel becker
2355aa6e12 Spread services across multiple groups 2025-08-16 18:58:02 +10:00
19 changed files with 185 additions and 50 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:
- managers
services_configs_dir: ""

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,8 +1,24 @@
server:
file-server:
hosts:
ec2-13-239-10-136.ap-southeast-2.compute.amazonaws.com:
debianpx:
ansible_host: 192.168.122.177
ansible_user: gabriel
ansible_become: yes
ansible_become_method: sudo
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 %
source_services_dir: /home/gabriel/hosted
server_services_dir: /home/srv/services/configs
PERSISTENT_DIRECTORY: /home/srv/services/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,46 +1,68 @@
---
- 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
- curl
- software-properties-common
- gnupg
- lsb-release
- python3-pip
- virtualenv
- python3-setuptools
state: latest
update_cache: true
- name: Add Docker GPG apt Key
apt_key:
- name: Download Docker GPG key
ansible.builtin.get_url:
url: https://download.docker.com/linux/debian/gpg
state: present
dest: /etc/apt/keyrings/docker.gpg
mode: '0644'
- name: Add Docker GPG key to apt keyring
ansible.builtin.shell: |
gpg --dearmor < /etc/apt/keyrings/docker.gpg > /etc/apt/keyrings/docker.gpg.gpg
chmod 644 /etc/apt/keyrings/docker.gpg.gpg
args:
creates: /etc/apt/keyrings/docker.gpg.gpg
- name: Add Docker Repository
apt_repository:
repo: deb https://download.docker.com/linux/debian bookworm stable
ansible.builtin.apt_repository:
repo: "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg.gpg] https://download.docker.com/linux/debian {{ ansible_distribution_release }} stable"
state: present
filename: docker
- 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:
name: docker-compose
state: latest
update_cache: true
- name: Install Docker Module for Python
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
- name: Ensure Docker service is started and enabled
ansible.builtin.service:
name: docker
state: started
enabled: true
- name: Ensure Docker Compose plugin is installed
ansible.builtin.apt:
name: docker-compose-plugin
state: latest
update_cache: 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

@ -1,11 +1,32 @@
---
- name: Ensure services destination directory exists
ansible.builtin.file:
path: "{{ server_services_dir }}"
state: directory
mode: '0755'
owner: "{{ ansible_user | default('root') }}"
group: "{{ ansible_user | default('root') }}"
- name: Copy service folder
ansible.posix.synchronize:
src: "{{ services_dir }}/{{ item }}"
dest: /services/
ansible.builtin.copy:
src: "{{ source_services_dir }}/{{ item }}"
dest: "{{ server_services_dir }}"
mode: '0755'
owner: "{{ ansible_user | default('root') }}"
group: "{{ ansible_user | default('root') }}"
with_items: "{{ services }}"
- name: Start Docker compose
community.docker.docker_compose:
project_src: "/services/{{ item }}"
- name: Docker Compose Start Service
community.docker.docker_compose_v2:
project_src: "{{ server_services_dir }}/{{ item }}"
# environment: "{{ compose_env }}"
check_files_existing: true
assume_yes: true
build: policy
wait: true
register: output
with_items: "{{ services }}"
async: 300
poll: 10

14
run.yml
View File

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