4.7 KiB
4.7 KiB
AGENTS GUIDE
Overview
Ansible-based server automation for personal services. Playbooks provision Dockerized apps (e.g., gitea, authelia, homepage, miniflux, wakapi, memos) via per-app users, Caddy proxy, and Yandex Docker Registry. Secrets are managed with Ansible Vault.
Project Layout
- Playbooks:
playbook-*.yml(per service),playbook-all-*.ymlfor grouped actions. - Inventory:
production.yml(ungrouped hostserver). - Variables:
vars/*.yml(app configs, images), secrets invars/secrets.yml(vault-encrypted). - Roles: custom roles under
roles/(e.g.,eget,owner,secrets) plus galaxy roles fetched togalaxy.roles/. - Files/templates: service docker-compose and backup templates under
files/, shared templates undertemplates/. - Scripts: helper Python scripts in
scripts/(SMTP utilities) andfiles/backups/backup-all.py. - CI:
.gitea/workflows/lint.ymlruns yamllint and ansible-lint. - Hooks:
lefthook.ymlreferences local hooks in/home/av/projects/private/git-hooks(gitleaks, vault check). - Formatting:
.editorconfigenforces LF, trailing newline, 4-space indent; YAML/Jinja use 2-space indent.
Setup
- Copy vault password sample:
cp ansible-vault-password-file.dist ansible-vault-password-file(needed for ansible and CI). - Install galaxy roles:
ansible-galaxy role install --role-file requirements.yml --force(ortask install-roles). - Ensure
yq,task,ansibleinstalled per README requirements.
Tasks (taskfile)
task install-roles— install galaxy roles intogalaxy.roles/.task ssh— SSH to target using inventory (production.yml).task btop— runbtopon remote.task encrypt|decrypt -- <files>— ansible-vault helpers.- Authelia helpers:
task authelia-cli -- <args>— run authelia CLI in docker.task authelia-validate-config— renderfiles/authelia/configuration.template.ymlwith secrets and validate via authelia docker image.task authelia-gen-random-string LEN=64— generate random string.task authelia-gen-secret-and-hash LEN=72— generate hashed secret.
task format-py-files— run Black via docker (pyfound/black).
Ansible Usage
- Inventory:
production.ymlwithserverhost.ansible.cfgpoints to./ansible-vault-password-fileand./galaxy.rolesfor roles path. - Typical deploy example (from README):
ansible-playbook -i production.yml --diff playbook-gitea.yml. - Per-app playbooks:
playbook-<app>.yml; grouped runs:playbook-all-setup.yml,playbook-all-applications.yml,playbook-upgrade.yml, etc. - Secrets: encrypted
vars/secrets.yml; additionalfiles/<app>/secrets.ymlused for templating (e.g., Authelia). Respect.crushignoreignoring vault files. - Templates: many
docker-compose.template.ymland*.template.shfiles underfiles/*plus sharedtemplates/env.j2. Usevars/*.ymlto supply values. - Custom roles:
roles/eget: installsegettool; see defaults/vars for version/source.roles/owner: manages user/group and env template.roles/secrets: manages vault-related items.
Linting & CI
- Local lint configs:
.yamllint.yml,.ansible-lint.yml(excludes.ansible/,.gitea/,galaxy.roles/,Taskfile.yml). - CI (.gitea/workflows/lint.yml) installs
yamllintandansible-lintand runsyamllint .thenansible-lint .; creates dummy vault file if missing. - Pre-commit via lefthook (local hooks path): runs
gitleaks git --stagedand secret-file vault check script.
Coding/Templating Conventions
- Indentation: 2 spaces for YAML/Jinja (
.editorconfig), 4 spaces default elsewhere. - End-of-line: LF; ensure final newline.
- Template suffixes
.template.yml,.yml.j2,.template.share rendered via Ansibletemplatemodule. - Avoid committing real secrets;
.crushignoreexcludesansible-vault-password-fileand*secrets.yml. - Service directories under
files/hold docker-compose and backup templates; ensure per-app users and registry settings align withvars/*.yml.
Testing/Validation
- YAML lint:
yamllint .(CI default). - Ansible lint:
ansible-lint .(CI default). - Authelia config validation:
task authelia-validate-config(renders with secrets then validates via docker). - Black formatting for Python helpers:
task format-py-files.
Operational Notes
- Deployments rely on
production.ymlinventory and per-app playbooks; run with--difffor visibility. - Yandex Docker Registry auth helper:
files/yandex-docker-registry-auth.sh. - Backups: templates and scripts under
files/backups/per service;backup-all.pyorchestrates. - Home network/DNS reference in README (Yandex domains).
- Ensure
ansible-vault-password-filepresent for vault operations and CI.