Skip to main content
The Vagrant connector generates pyinfra inventory from running Vagrant VMs. This enables easy integration between Vagrant for local development and pyinfra for configuration management.

Overview

The Vagrant connector automatically detects running Vagrant VMs and generates inventory with SSH connection details.

Requirements

  • Vagrant installed and accessible
  • One or more running Vagrant VMs
  • Current directory contains Vagrantfile (or specify path)

Basic Usage

All Running VMs

Specific VM

Multiple VMs

Vagrantfile Example

A typical multi-machine Vagrantfile:

Configuration

The connector reads SSH configuration from vagrant ssh-config:
Pyinfra automatically uses these settings.

Custom Options

Provide additional host data via @vagrant.json:

Deployment Workflow

Typical Vagrant + pyinfra workflow:

Testing Deploys Locally

Use Vagrant to test deploys before running on production:

Multi-Machine Examples

Web + Database Setup

Load Balanced Web Cluster

Inventory API

Use in Python API:

Checking VM Status

Limitations

  • Only detects VMs in “running” state
  • Must run from directory containing Vagrantfile
  • Slower than SSH connector (queries Vagrant for each VM)
  • Requires Vagrant in PATH

Troubleshooting

No VMs Found

Connection Errors

Slow Performance

The Vagrant connector queries vagrant ssh-config for each VM, which can be slow:

Comparison with SSH Connector

Source Reference

Location: src/pyinfra/connectors/vagrant.py:90

Key Methods

  • make_names_data() - Generate hosts from Vagrant
  • get_vagrant_config() - Read Vagrant SSH config (line 30)
  • get_vagrant_options() - Read @vagrant.json (line 83)