Day 29: Provisioning with Shell Scripts

Today marks a shift in my DevOps journey β€” moving from manual configuration to automated provisioning using Vagrant and shell scripts.


🧱 The Challenge with Manual Setup

Last week, I provisioned:

  • MySQL

  • Memcached

  • RabbitMQ

  • Tomcat

  • Nginx

...manually in multi-stage VMs using Vagrant. While this helped me understand how each service works, it’s not practical to repeat it over and over.


βœ… Automating with .sh Provision Scripts

To make the setup reusable and reproducible, I created individual shell scripts for each service:

β”œβ”€β”€ Vagrantfile
β”œβ”€β”€ provisioning/
β”‚   β”œβ”€β”€ db-provision.sh
β”‚   β”œβ”€β”€ mc-provision.sh
β”‚   β”œβ”€β”€ rmq-provision.sh
β”‚   β”œβ”€β”€ app-provision.sh
β”‚   └── web-provision.sh

Each .sh script handles everything from package installation to firewall configuration for its service.


πŸ“¦ Example Vagrantfile (Multi-VM with Shell Provisioning)

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "generic/centos7"

  config.vm.define "db01" do |db|
    db.vm.hostname = "db01"
    db.vm.network "private_network", ip: "192.168.56.11"
    db.vm.provision "shell", path: "provisioning/db-provision.sh"
  end

  config.vm.define "mc01" do |mc|
    mc.vm.hostname = "mc01"
    mc.vm.network "private_network", ip: "192.168.56.12"
    mc.vm.provision "shell", path: "provisioning/mc-provision.sh"
  end

  config.vm.define "rmq01" do |rmq|
    rmq.vm.hostname = "rmq01"
    rmq.vm.network "private_network", ip: "192.168.56.13"
    rmq.vm.provision "shell", path: "provisioning/rmq-provision.sh"
  end

  config.vm.define "app01" do |app|
    app.vm.hostname = "app01"
    app.vm.network "private_network", ip: "192.168.56.14"
    app.vm.provision "shell", path: "provisioning/app-provision.sh"
  end

  config.vm.define "web01" do |web|
    web.vm.hostname = "web01"
    web.vm.network "private_network", ip: "192.168.56.15"
    web.vm.provision "shell", path: "provisioning/web-provision.sh"
  end
end

πŸš€ Benefits So Far

  • πŸ” Repeatable setup across environments

  • 🧩 Modular configuration for each service

  • πŸ“‚ Easy debugging and reusability

  • πŸ’¨ Faster deployment compared to manual setup


🎯 What’s Next?

In the next steps, I’ll dive into basics of networking

0
Subscribe to my newsletter

Read articles from Shaharyar Shakir directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Shaharyar Shakir
Shaharyar Shakir