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 .venv
.vscode .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 ## Usage
```bash ```bash
ansible-playbook run.yml ansible-playbook run.yml
ansible-playbook run.yml --ask-pass --ask-become-pass
ansible-playbook run.yml --vault-password-file .vault_pass
``` ```
## Variables ## Variables
Should be defined in `group_vars/server/vars.yml`: 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 - **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 group_services:
- htop # - pinry
services: # - piped
- pinry # - immich
- immich # - monica
- monica # - piwigo
- piwigo # - vikunja
- vikunja - syncthing
services_dir: /home/gabriel/hosted 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: 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: vars:
ansible_user: admin source_services_dir: /home/gabriel/hosted
ansible_ssh_private_key_file: /home/gabriel/dev/terraform/terraform-lab/ec2ml/my_ssh.pem server_services_dir: /home/srv/services/configs
PERSISTENT_DIRECTORY: /persistent PERSISTENT_DIRECTORY: /home/srv/services/persistent
VOLATILE_DIRECTORY: /volatile % # 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 - name: Update packages
apt: ansible.builtin.apt:
update_cache: yes update_cache: true
upgrade: yes upgrade: true
- name: Install essential packages - name: Install essential packages
package: ansible.builtin.package:
name: "{{ packages }}" name: "{{ packages }}"
state: latest state: latest

View File

@ -1,46 +1,68 @@
--- ---
- name: Install aptitude - name: Install aptitude
apt: ansible.builtin.apt:
name: aptitude name: aptitude
state: latest state: latest
update_cache: true update_cache: true
- name: Install required system packages - name: Install required system packages
apt: ansible.builtin.apt:
pkg: pkg:
- apt-transport-https - apt-transport-https
- ca-certificates - ca-certificates
- curl - curl
- software-properties-common - gnupg
- lsb-release
- python3-pip - python3-pip
- virtualenv - virtualenv
- python3-setuptools - python3-setuptools
state: latest state: latest
update_cache: true update_cache: true
- name: Add Docker GPG apt Key - name: Download Docker GPG key
apt_key: ansible.builtin.get_url:
url: https://download.docker.com/linux/debian/gpg 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 - name: Add Docker Repository
apt_repository: ansible.builtin.apt_repository:
repo: deb https://download.docker.com/linux/debian bookworm stable repo: "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg.gpg] https://download.docker.com/linux/debian {{ ansible_distribution_release }} stable"
state: present state: present
filename: docker
- name: Update apt and install docker-ce - name: Update apt and install docker-ce
apt: ansible.builtin.apt:
name: docker-ce name: docker-ce
state: latest state: latest
update_cache: true 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 - name: Install Docker Module for Python
ansible.builtin.pip: ansible.builtin.pip:
name: docker name: docker
extra_args: --break-system-packages 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 - ansible.builtin.include_tasks: dependencies.yml
- include_tasks: install_docker.yml - ansible.builtin.include_tasks: install_docker.yml
- include_tasks: start_service.yml - ansible.builtin.include_tasks: start_service.yml
- include_tasks: nginx_config.yml - ansible.builtin.include_tasks: nginx_config.yml

View File

@ -1,6 +1,6 @@
--- ---
- name: Copy service folder - name: Copy service folder
copy: ansible.builtin.copy:
src: "{{ services_dir }}/nginx-npm" src: "{{ services_dir }}/nginx-npm"
dest: /services/ 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 - name: Copy service folder
ansible.posix.synchronize: ansible.builtin.copy:
src: "{{ services_dir }}/{{ item }}" src: "{{ source_services_dir }}/{{ item }}"
dest: /services/ dest: "{{ server_services_dir }}"
mode: '0755'
owner: "{{ ansible_user | default('root') }}"
group: "{{ ansible_user | default('root') }}"
with_items: "{{ services }}" with_items: "{{ services }}"
- name: Start Docker compose - name: Docker Compose Start Service
community.docker.docker_compose: community.docker.docker_compose_v2:
project_src: "/services/{{ item }}" 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 }}" with_items: "{{ services }}"
async: 300
poll: 10

14
run.yml
View File

@ -1,5 +1,17 @@
--- ---
- hosts: server - 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: roles:
- role: webserver - role: webserver