Skip to content

Add JSON output to provision command #352

@josecelano

Description

@josecelano

Overview

Add machine-readable JSON output format (--output-format json) to the provision command. This enables automation workflows to programmatically extract the provisioned instance IP address and connection details without regex parsing of console output.

Specification: docs/issues/352-add-json-output-to-provision-command.md

Parent Epic: #348 - Add JSON output format support
Related: #349 (completed reference implementation for create command)
Roadmap: Section 12.2

Goals

  • Implement JSON output format for provision command
  • Preserve existing human-readable output as default
  • Enable automation to extract instance IP reliably
  • Follow the architecture pattern established in Add JSON Output to create Command #349

Key Features

JSON Output

torrust-tracker-deployer provision my-env --output-format json

Returns:

{
  "environment_name": "my-env",
  "instance_name": "torrust-tracker-vm-my-env",
  "instance_ip": "10.140.190.39",
  "ssh_username": "torrust",
  "ssh_port": 22,
  "ssh_private_key_path": "/path/to/key",
  "provider": "lxd",
  "provisioned_at": "2026-02-16T16:00:00Z",
  "domains": ["tracker.example.com"]
}

Critical Fields

  • instance_ip: Most important for automation - enables automated workflows
  • ssh_private_key_path: Enables automated SSH connections without manual key management
  • domains: Enables automated DNS record updates for HTTPS deployments

Architecture

Implementation Phases

  1. Phase 0: Study create command reference implementation
  2. Phase 1: Create ProvisionDetailsData DTO
  3. Phase 2: Implement TextView and JsonView
  4. Phase 3: Wire format switching in controller
  5. Phase 4: Update tests
  6. Phase 5: Testing and validation
  7. Phase 6: Documentation

Automation Use Cases

  1. SSH Connection Automation: Extract IP + credentials for automated SSH testing
  2. DNS Update Automation: Update DNS records immediately after provisioning
  3. Complete Deployment Pipeline: Provision → DNS → Wait for SSH → Configure → Release → Run

Acceptance Criteria

  • ✅ JSON output with --output-format json flag
  • ✅ Default text output unchanged
  • ✅ All fields present and correct
  • ✅ Works with both LXD and Hetzner providers
  • ✅ Progress logs to stderr, JSON to stdout
  • ✅ Pre-commit checks pass
  • ✅ Documentation updated

Related Documentation

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions