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
Subscribe to my newsletter
Read articles from Shaharyar Shakir directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
