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
Recommended Articles
Bonnes pratiques Vagrant : des environnements reproductibles et rapides
Bonnes pratiques Vagrant : Vagrantfile versionné, boxes épinglées, provisioning idempotent, multi...