RousselTMLEARNING

TP · Vagrant: From Discovery to Expertise

Lab: A multi-machine environment (web + database)

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. 1. Describe the two machines

    Why? A loop over a nodes table avoids duplicating configuration: adding a machine means adding one line.

    Create web (192.168.56.11) and db (192.168.56.12) from a Ruby loop.
  2. 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 on web and PostgreSQL on db through an idempotent shell provisioner.
  3. 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.

    From web, reach db on the PostgreSQL port.
  4. 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

  • ⏱ Estimated time : ≈ 35 min

Sign in to track your progress and take notes. Sign in

✉️ Ask a question

Recommended Articles

Bonnes pratiques Vagrant : des environnements reproductibles et rapides

Bonnes pratiques Vagrant : Vagrantfile versionné, boxes épinglées, provisioning idempotent, multi...