What you will learn in this TP
- Define several machines in a Vagrantfile
- Provision automatically
- Check machine-to-machine connectivity
The multi-machine Vagrantfile #
What you will learn in this section
- Define several machines in a Vagrantfile
- Provision automatically
- Check machine-to-machine connectivity
Context. The application has a web front end and a database that must communicate. Reproducing this topology on a developer machine, with two VMs on a private network, avoids "it worked locally" surprises at deployment.
Prerequisites: Previous lab, networking basics (IP, ports) · Estimated time: 35 min
Two nodes, one network, one provisioning.1. Describe the two machines
Why? A loop over a nodes table avoids duplicating configuration: adding a machine means adding one line.
Createweb(192.168.56.11) anddb(192.168.56.12) from a Ruby loop.2. Provision with a script
Why? Installing software by hand makes the environment non-reproducible; a provisioner does it at each creation, identically for everyone.
Install nginx onweband PostgreSQL ondbthrough an idempotentshellprovisioner.3. Check connectivity
Why? Testing ping then the TCP port distinguishes a network problem from a service problem: the first fails for the former, the second for the latter.
Fromweb, reachdbon the PostgreSQL port.4. Replay without breaking anything
Why? Provisioning must be replayable without breaking the machine: that is idempotency, essential when fixing configuration.
Re-run provisioning on one machine: what happens (idempotency)?
Difficulty level : ●●○○○ (2/5)
My progress
Sign in to track your progress and take notes. Sign in
💬 Questions about this lesson
No questions yet: be the first to ask for help or share your configuration.
Recommended Articles
Vagrant best practices: reproducible and fast environments
Vagrant best practices: versioned Vagrantfile, pinned boxes, idempotent provisioning, multi-machi...
Vagrant multi-machine: deploying a ready-to-use Docker Swarm cluster
Use a single Vagrantfile to build a three-node Docker Swarm cluster (one manager, two workers) wi...
Sharing a Vagrant environment: ngrok and the vagrant-share plugin
Make an application running in a Vagrant machine accessible to a colleague or a client: port forw...
Vagrant: overview and vocabulary (box, provider, provisioner, Vagrantfile)
The essential notions for following the Vagrant course: what Vagrant is for, the lifecycle of an ...
Compute on Azure: virtual machines, App Service, Functions and containers
Choose and use Azure compute: virtual machines and scale sets (VMSS), App Service, Azure Function...
Vagrant plugins: extending providers, provisioners and commands
Understand Vagrant's plugin system: what a plugin can add (provider, provisioner, command, capabi...
Ansible: managing your infrastructure with playbooks (Infrastructure as Code)
Write production playbooks: project structure, plays, handlers, tags, serial strategy, error hand...
Terraform multi-environment, workspaces and repository organization
Organize Terraform for several environments: one folder per environment, tfvars files, CLI worksp...
Ansible: going further (testing, quality, CI/CD and performance)
Industrialize Ansible: ansible-lint, yamllint, Molecule, continuous integration, collections, exe...