Skip to content

Variables

Variables let you define values once and reuse them. Ansible loads them automatically based on the file location:

  • group_vars/all.yml applies to every host.
  • group_vars/infra.yml applies only to hosts in the [infra] group.
  • host_vars/nas.example.com.yml applies only to nas.

inventory/group_vars/all.yml

Shared across all hosts: the user, timezone/locale, the package list, directory paths, backup targets and NAS connection details. An excerpt:

---
# User
main_user: username

# Timezone
timezone: <TZ>

# Docker directory structure
docker_compose_dir: /opt/docker
appdata_dir: /mnt/appdata
backup_mount: /mnt/backups

# NAS backup
nas_backup_host: "nas.example.com"
nas_samba_user: username
# the samba password is stored in ansible vault (see Vault)

The complete file is in the worked example: Base Configuration → inventory/group_vars/all.yml. Secrets go in the vault, never here.

inventory/group_vars/infra.yml

Specific to server1.

---
# Infra-specific stacks to deploy
infra_stacks:
  - npm
  - cloudflared
  - homeassistant
  - monitoring
  - homepage
  - code-server
  - vaultwarden

inventory/group_vars/apps.yml

Specific to server2.

---
# App-specific stacks to deploy
app_stacks:
  - affine
  - vikunja
  - trilium
  - utilities
  - omada
  - paperless
  - forgejo
  - socket-proxy

inventory/host_vars/nas.example.com.yml

nas-specific overrides (not fully managed by Ansible, just borgmatic + cleanup).

---
docker_compose_dir: /opt/docker
appdata_dir: /mnt/appdata
# nas doesn't mount NAS backups (it IS the NAS)
skip_nas_mount: true
borg_repo_path: /path/to/backups/borg/nas