vps-forge
Idempotent, rollback-safe VPS provisioning framework (Ansible + Python CLI).
Installation
- PyPI:
pip install vps-forge ansible-galaxy collection install ansible.posix community.general
- npm (CLI wrapper):
npx @yangdw2024/vps-forge --help
- From source / GitHub Release template:
git clone https://github.com/yangdw2024/VPSForge.git cd VPSForge make setup
Architecture
- Declarative Config (
config.yaml): Single source of truth for global baseline settings and per-node topology/modules, initialized fromconfig.example.yaml(which includes Chinese inline comments matching the Chinese CLI UX). - Python Control Plane (
vps_forge/):schema.py: Pydantic v2 validation forglobal,nodes[], pluggable modules (caddy_tls,proxy_stack,monitor),module_vars, unique node names, andrelay->landingtopology checks.cli.py:init,apply(--dry-run,--tags,--limit),doctor, anddoctor --deep; per-node isolated WSL2 key permission mirroring (0600); live SSH port detection; compilation ofansible/inventory/hosts.ymlandansible/inventory/host_vars/<node>.yml; persistentproxy_stacksecrets and client artifacts underoutput/; native Windows execution interception with WSL2 guidance.exporter.py: Pure-stdlib.ziptemplate package exporter (python -m vps_forge.exporter).
- Ansible Provisioning Plane (
ansible/):preflight: Read-only OS/hardware checks (Debian/Ubuntu).hardening: Non-root sudo user, Ubuntussh.socketadaptation, mergedsshd -tvalidation with rollback cleanup, UFW, Fail2ban, and asystemd-runanti-lockout rollback timer (rollback_timeout_sec). Safe for first-run--dry-run(--check) against a blank VPS.docker_base: Timezone, container-safe BBR sysctl tuning, auto Swap (< 2GB RAM), Docker Engine + log rotation.roles/modules/{caddy_tls,proxy_stack,monitor}: Pluggable Docker Compose business modules gated byenabled_modules, all--check-safe and idempotent across re-runs.
- Verification & Distribution (
scripts/,docker/,Makefile):- Stage 3 local container smoke test (
make smoke-test) and Stage 4 clean template export (make export-template).
- Stage 3 local container smoke test (
Quick Start (WSL2 / Linux / macOS)
Windows users: Ansible cannot act as a control node on native Windows. Running
vps-forge applyon native Windows prints the exact WSL2 command to execute.
# 1. One-shot setup in WSL2 Ubuntu (creates .venv, installs dev deps & Ansible collections)
make setup
# 2. Verify local toolchain & Ansible playbook syntax
make syntax-check
make lint
make test
# 3. Generate and edit config.yaml
.venv/bin/vps-forge init
# Edit config.yaml with your VPS IP, SSH keys, ports, and enabled modules
# 4. Dry-run, deploy, and verify (without touching local proxy/routing/DNS)
make dry-run
make apply
make doctor
make doctor-deep
# 5. Stage 3 local container smoke test & Stage 4 clean template export
make smoke-test
make export-template
Configuration & Pluggable Modules
Each node in config.yaml supports modules drawn from: docker_base, caddy_tls, proxy_stack, monitor, plus optional per-node module_vars overrides.
caddy_tls
Docker Compose Caddy deployment (caddy:2-alpine, container vps-forge-caddy) for automatic ACME HTTPS issuance/renewal, internal TLS, reverse proxy, or masquerade site hosting.
enabled(true),domain(default"localhost"; required whentls_mode: acme),email(null)tls_mode:"acme"|"internal"|"off"(default"acme")mode:"reverse_proxy"|"masquerade"|"both"(default"reverse_proxy")upstream("127.0.0.1:8080"),masquerade_root("/srv/www"),masquerade_title("Welcome"),http_port(80),https_port(443)
proxy_stack
Docker Compose sing-box deployment (ghcr.io/sagernet/sing-box:v1.10.7, container vps-forge-proxy) supporting single-node standalone, multi-node relay -> landing chaining, and upstream_proxy residential SOCKS/HTTP egress chaining.
enabled(true),mode:"standalone"|"relay"|"landing"(default"standalone")protocol:"vless_ws"|"trojan"|"shadowsocks"(default"vless_ws")listen_host("0.0.0.0"),listen_port(10443),ws_path("/ws"),public_host(null),public_port(null)landing_node(required whenmode: relay; must reference a node withproxy_stackinlandingorstandalonemode)upstream_proxy(optional{type: "socks" | "http", host, port, username?, password?})uuid/password(auto-generated and persisted underoutput/if omitted),local_socks_port(10808)
# Example: standalone with upstream residential proxy
nodes:
- name: edge-1
host: 203.0.113.10
ssh_private_key: ~/.ssh/id_ed25519
ssh_public_key: ~/.ssh/id_ed25519.pub
modules: [docker_base, caddy_tls, proxy_stack, monitor]
caddy_tls:
domain: edge.example.com
email: ops@example.com
tls_mode: acme
mode: reverse_proxy
upstream: 127.0.0.1:10443
proxy_stack:
mode: standalone
protocol: vless_ws
listen_port: 10443
ws_path: /ws
upstream_proxy:
type: socks
host: 198.51.100.20
port: 1080
monitor:
listen_host: 127.0.0.1
port: 9100
health_port: 9101
check_containers: [vps-forge-caddy, vps-forge-proxy]
# Example: relay -> landing topology
nodes:
- name: tokyo-relay
role: relay
host: 203.0.113.11
ssh_private_key: ~/.ssh/id_ed25519
ssh_public_key: ~/.ssh/id_ed25519.pub
modules: [docker_base, proxy_stack]
proxy_stack:
mode: relay
protocol: vless_ws
listen_port: 10443
landing_node: us-landing
- name: us-landing
role: landing
host: 198.51.100.30
ssh_private_key: ~/.ssh/id_ed25519
ssh_public_key: ~/.ssh/id_ed25519.pub
modules: [docker_base, proxy_stack]
proxy_stack:
mode: landing
protocol: vless_ws
listen_port: 10443
monitor
Docker Compose node & service monitoring (prom/node-exporter:v1.8.2, container vps-forge-monitor) plus an HTTP /healthz sidecar bound to localhost by default.
enabled(true),listen_host("127.0.0.1"),port(9100),health_port(9101),scrape_interval_sec(15),check_containers([])
module_vars
Optional per-node dictionary (module_vars: {}) merged into ansible/inventory/host_vars/<node>.yml for custom Ansible variable overrides.
Deployment, Client Artifacts & Diagnostics
- Dry-run vs Apply:
make dry-run(vps-forge apply -c config.yaml --dry-run) executes Ansible--check --diffsafely even against blank hosts and never writes secrets/configs intooutput/.make apply(vps-forge apply -c config.yaml) compilesansible/inventory/hosts.ymlandansible/inventory/host_vars/<node>.ymland applies all enabled roles.vps-forge applyalso accepts--tagsand--limit.
- Client Artifacts (
output/, ignored by.gitignore):output/<node>/credentials.json: Persisteduuid,password,protocol,mode(reused on subsequent runs for idempotency unless overridden inconfig.yaml).output/<node>/client.json: Generatedsing-boxclient configuration.output/<node>/links.txt: Shareable client URIs.output/summary.json: Node topology and endpoint summary.
- Diagnostics (
doctor&doctor --deep):make doctor: Local non-intrusive TCP reachability probe.make doctor-deep: Read-only SSH diagnostic reporting host baseline (SSH_PORTS,UFW_STATUS,UFW_RULES,BBR,FAIL2BAN,DOCKER,MEM,DISK), container health (CONTAINERS_RUNNING,CONTAINERS_TOTAL,CONTAINERS_UNHEALTHY,CONTAINER_DETAILS), and remote-side read-only egress (EGRESS_DIRECT,EGRESS_PROXYvia remote127.0.0.1:<local_socks_port>).
Stage 3: Local Container Smoke Test
Run make smoke-test in WSL2 Ubuntu to execute scripts/smoke_test.py against local container target(s), verifying:
- First-run
--dry-run(--check) zero-error compatibility. - Full
applydeployment across enabled modules (caddy_tls,proxy_stack,monitor). - Container health and
doctor --deepread-only inspection. - Second-run idempotency (
changed=0/ stable state) and automated cleanup.
Stage 4: Clean Template Export & Makefile Reference
Export a clean, distributable .zip template package without git or /usr/bin/zip:
make export-template
# or directly:
.venv/bin/python -m vps_forge.exporter --root . --output dist/vps-forge-template.zip
- Included:
Makefile,pyproject.toml,README.md,config.example.yaml,.gitignore,vps_forge/,ansible/(excludingansible/inventory/),scripts/,docker/, andtests/. - Excluded:
.venv/,venv/,config.yaml,ansible/inventory/,output/,.git/,__pycache__/,.pytest_cache/,.ruff_cache/,.mypy_cache/,*.pyc,*.pyo,*.pyd,*$py.class,*.egg-info/,dist/,build/,.agents/,.vscode/,.idea/,.DS_Store,Thumbs.db,*.zip, symlinks, and the output archive itself.
| Target | Purpose |
|---|---|
make help |
List all available Makefile targets |
make setup |
Create .venv, install project/dev dependencies, and install Ansible collections |
make lint |
Run ruff check vps_forge tests |
make test |
Run pytest -v unit tests |
make syntax-check |
Run ansible-playbook --syntax-check on ansible/site.yml |
make dry-run |
Run vps-forge apply -c $(CONFIG) --dry-run |
make apply |
Run vps-forge apply -c $(CONFIG) |
make doctor |
Run local TCP port probe |
make doctor-deep |
Run read-only SSH host, container health, and remote egress probe |
make smoke-test |
Run Stage 3 local container smoke test (scripts/smoke_test.py) |
make export-template |
Export clean project .zip template to $(EXPORT_OUTPUT) |
make clean |
Remove caches and build//dist/ artifacts (preserves .venv, config.yaml, output/, ansible/inventory/) |
Operational Safety Rules
- WSL2 Control Plane: Run provisioning and
makecommands inside WSL2 Ubuntu (or Linux/macOS); native Windowsapplyis safely intercepted. - Anti-Lockout Protection: SSH hardening uses a
systemd-runrollback timer (rollback_timeout_sec), mergedsshd -tvalidation in ablock/rescueflow, and live SSH port detection. - Zero Local Network Mutations:
vps-forge(apply,doctor --deep,smoke-test, and tests) never modifies local host proxy settings, routing tables, or DNS configuration.
Metadata
Release files for vps-forge 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| vps_forge-0.1.1.tar.gz | 129.7 kB | Without provenance | Details for vps_forge-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| vps_forge-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for vps_forge-0.1.1-py3-none-any.whl |
Total release size: 183.4 kB
Release files / vps_forge-0.1.1.tar.gz
| Download URL | vps_forge-0.1.1.tar.gz |
|---|---|
| Size | 129.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c691f1bf4a9fa8bca9a66ac39f121a20eb2c3c120d9248f24804df41f8e4aac1
|
|
BLAKE2b-256 checksum How to use checksums |
23e0dc43724b8cfb9b7f2c9b872ff0911dc482cca274f70bc65f36d57257e9f6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.13
|
Release files / vps_forge-0.1.1-py3-none-any.whl
| Download URL | vps_forge-0.1.1-py3-none-any.whl |
|---|---|
| Size | 53.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
981f2fa0b4364bec979e39ae65dbc2c9d21447a1365acc2fb2a84e264b8a83d5
|
|
BLAKE2b-256 checksum How to use checksums |
f159107f3223379e06e853b88c7b7ca067545cbbff90fa0580a1ac817b67c566
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.13
|
Security for vps-forge 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.