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 fromvagrant ssh-config:
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
Troubleshooting
No VMs Found
Connection Errors
Slow Performance
The Vagrant connector queriesvagrant 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 Vagrantget_vagrant_config()- Read Vagrant SSH config (line 30)get_vagrant_options()- Read @vagrant.json (line 83)
