In this blog, we will take you through the process of configuring a small Ansible environment using Vagrant. Vagrant provides a solution for creating disposable or sandbox virtual dev environments, all within a single Vagrantfile, which closely mimics the production environment. We define everything we need in a VM in the Vagrantfile and Vagrant will take care of configuring those in the VM.
Vagrant uses a concept of base images for operating systems that are customised and stored in a public Vagrant repository, and for this configuration, we will be using the standard RHEL9 image.
Lab Configuration
We have the following VMs created which will be later used for the Ansible Tower configuration.
Hostname | Role | IP Address |
aap | Ansible Automation Provider | 10.0.2.50 |
haproxy | Load Balancer | 10.0.2.51 |
webserver01 | Web Server | 10.0.2.52 |
webserver01 | Web Server | 10.0.2.53 |
db | Database Server | 10.0.2.54 |
How to Manage Vagrant
Here are some useful Vagrant commands to manage our VM’s.
vagrant version | Show version of Vagrant |
vagrant init <image name> | Initialize the Vagrantfile eg: generic/rhel9 |
vagrant up <VM name> | Launches the VM |
vagrant halt <VM name> | Shutdown the VM |
vagrant reload | Restarts the VM |
vagrant status | Show the current state of the VM |
vagrant ssh | ssh connection to VM |
vagrant destroy <VM name> | Delete the VM |
Prerequisites for Installing Vagrant
Vagrant is a wrapper utility that works on top of Virtual machine solutions like Oracle Virtualbox, HyperV, VMware, Docker etc.
- Download and Install Virtual Box from the Oracle website
- Download the Vagrant installer file
Create a Lab Environment with Vagrant
Create a directory to define and hold the configuration necessary for Vagrant to run. Our defined Vagrant file is added to this location and Vagrant uses the configuration in the Vagrantfile to build out the VM’s
Define the Vagrantfile for Multiple Vagrant VMs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
<span class="line"><span style="color: #EEFFFF"># Ansible Deployment Lab Servers for Virtual Box </span></span> <span class="line"></span> <span class="line"><span style="color: #EEFFFF"># Deploy Ansible Automation Provider </span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF"> AAP </span></span> <span class="line"><span style="color: #EEFFFF">Vagrant</span><span style="color: #89DDFF">.</span><span style="color: #82AAFF">configure</span><span style="color: #EEFFFF">(</span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">2</span><span style="color: #89DDFF">"</span><span style="color: #EEFFFF">) </span><span style="color: #89DDFF; font-style: italic">do</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">|</span><span style="color: #EEFFFF">config</span><span style="color: #89DDFF">|</span></span> <span class="line"><span style="color: #EEFFFF"> config</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">vm</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">define </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">aap</span><span style="color: #89DDFF">"</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF; font-style: italic">do</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">|</span><span style="color: #EEFFFF">aap</span><span style="color: #89DDFF">|</span></span> <span class="line"><span style="color: #EEFFFF"> aap</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">vm</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">box </span><span style="color: #89DDFF">=</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">generic/rhel9</span><span style="color: #89DDFF">"</span></span> <span class="line"><span style="color: #EEFFFF"> aap</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">vm</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">hostname </span><span style="color: #89DDFF">=</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">'</span><span style="color: #C3E88D">aap</span><span style="color: #89DDFF">'</span></span> <span class="line"><span style="color: #EEFFFF"> aap</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">vm</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">box_url </span><span style="color: #89DDFF">=</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">generic/rhel9</span><span style="color: #89DDFF">"</span></span> <span class="line"><span style="color: #EEFFFF"> aap</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">vm</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">network :private_network</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> </span><span style="color: #FFCB6B">ip</span><span style="color: #89DDFF">:</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">10.0.2.50</span><span style="color: #89DDFF">"</span></span> <span class="line"><span style="color: #EEFFFF"> aap</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">vm</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">provider :virtualbox </span><span style="color: #89DDFF; font-style: italic">do</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">|</span><span style="color: #EEFFFF">v</span><span style="color: #89DDFF">|</span></span> <span class="line"><span style="color: #EEFFFF"> v</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">customize [</span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">modifyvm</span><span style="color: #89DDFF">"</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> :id</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">--natdnshostresolver1</span><span style="color: #89DDFF">"</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">on</span><span style="color: #89DDFF">"</span><span style="color: #EEFFFF">]</span></span> <span class="line"><span style="color: #EEFFFF"> v</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">customize [</span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">modifyvm</span><span style="color: #89DDFF">"</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> :id</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">--memory</span><span style="color: #89DDFF">"</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> </span><span style="color: #F78C6C">1024</span><span style="color: #EEFFFF">]</span></span> <span class="line"><span style="color: #EEFFFF"> v</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">customize [</span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">modifyvm</span><span style="color: #89DDFF">"</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> :id</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">--name</span><span style="color: #89DDFF">"</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">aap</span><span style="color: #89DDFF">"</span><span style="color: #EEFFFF">]</span></span> <span class="line"><span style="color: #EEFFFF"> end</span></span> <span class="line"><span style="color: #EEFFFF"> end</span></span> <span class="line"><span style="color: #EEFFFF"># Deploy Load Balancer</span></span> <span class="line"><span style="color: #EEFFFF"> config</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">vm</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">define </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">haproxy</span><span style="color: #89DDFF">"</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF; font-style: italic">do</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">|</span><span style="color: #EEFFFF">haproxy</span><span style="color: #89DDFF">|</span></span> <span class="line"><span style="color: #EEFFFF"> haproxy</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">vm</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">box </span><span style="color: #89DDFF">=</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">generic/rhel9</span><span style="color: #89DDFF">"</span></span> <span class="line"><span style="color: #EEFFFF"> haproxy</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">vm</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">hostname </span><span style="color: #89DDFF">=</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">'</span><span style="color: #C3E88D">haproxy</span><span style="color: #89DDFF">'</span></span> <span class="line"><span style="color: #EEFFFF"> haproxy</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">vm</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">box_url </span><span style="color: #89DDFF">=</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">generic/rhel9</span><span style="color: #89DDFF">"</span></span> <span class="line"><span style="color: #EEFFFF"> haproxy</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">vm</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">network :private_network</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> </span><span style="color: #FFCB6B">ip</span><span style="color: #89DDFF">:</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">10.0.2.51</span><span style="color: #89DDFF">"</span></span> <span class="line"><span style="color: #EEFFFF"> haproxy</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">vm</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">provider :virtualbox </span><span style="color: #89DDFF; font-style: italic">do</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">|</span><span style="color: #EEFFFF">v</span><span style="color: #89DDFF">|</span></span> <span class="line"><span style="color: #EEFFFF"> v</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">customize [</span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">modifyvm</span><span style="color: #89DDFF">"</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> :id</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">--natdnshostresolver1</span><span style="color: #89DDFF">"</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">on</span><span style="color: #89DDFF">"</span><span style="color: #EEFFFF">]</span></span> <span class="line"><span style="color: #EEFFFF"> v</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">customize [</span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">modifyvm</span><span style="color: #89DDFF">"</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> :id</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">--memory</span><span style="color: #89DDFF">"</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> </span><span style="color: #F78C6C">1024</span><span style="color: #EEFFFF">]</span></span> <span class="line"><span style="color: #EEFFFF"> v</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">customize [</span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">modifyvm</span><span style="color: #89DDFF">"</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> :id</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">--name</span><span style="color: #89DDFF">"</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">haproxy</span><span style="color: #89DDFF">"</span><span style="color: #EEFFFF">]</span></span> <span class="line"><span style="color: #EEFFFF"> end</span></span> <span class="line"><span style="color: #EEFFFF"> end</span></span> <span class="line"><span style="color: #EEFFFF"># Deploy WebServer01</span></span> <span class="line"><span style="color: #EEFFFF"> config</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">vm</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">define </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">web01</span><span style="color: #89DDFF">"</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF; font-style: italic">do</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">|</span><span style="color: #EEFFFF">web01</span><span style="color: #89DDFF">|</span></span> <span class="line"><span style="color: #EEFFFF"> web01</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">vm</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">box </span><span style="color: #89DDFF">=</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">generic/rhel9</span><span style="color: #89DDFF">"</span></span> <span class="line"><span style="color: #EEFFFF"> config</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">vm</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">provision :shell</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> </span><span style="color: #FFCB6B">path</span><span style="color: #89DDFF">:</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">web01config.sh</span><span style="color: #89DDFF">"</span></span> <span class="line"><span style="color: #EEFFFF"> web01</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">vm</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">hostname </span><span style="color: #89DDFF">=</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">'</span><span style="color: #C3E88D">web01</span><span style="color: #89DDFF">'</span></span> <span class="line"><span style="color: #EEFFFF"> web01</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">vm</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">box_url </span><span style="color: #89DDFF">=</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">generic/rhel9</span><span style="color: #89DDFF">"</span></span> <span class="line"><span style="color: #EEFFFF"> web01</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">vm</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">network :private_network</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> </span><span style="color: #FFCB6B">ip</span><span style="color: #89DDFF">:</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">10.0.2.52</span><span style="color: #89DDFF">"</span></span> <span class="line"><span style="color: #EEFFFF"> web01</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">vm</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">provider :virtualbox </span><span style="color: #89DDFF; font-style: italic">do</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">|</span><span style="color: #EEFFFF">v</span><span style="color: #89DDFF">|</span></span> <span class="line"><span style="color: #EEFFFF"> v</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">customize [</span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">modifyvm</span><span style="color: #89DDFF">"</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> :id</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">--natdnshostresolver1</span><span style="color: #89DDFF">"</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">on</span><span style="color: #89DDFF">"</span><span style="color: #EEFFFF">]</span></span> <span class="line"><span style="color: #EEFFFF"> v</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">customize [</span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">modifyvm</span><span style="color: #89DDFF">"</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> :id</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">--memory</span><span style="color: #89DDFF">"</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> </span><span style="color: #F78C6C">1024</span><span style="color: #EEFFFF">]</span></span> <span class="line"><span style="color: #EEFFFF"> v</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">customize [</span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">modifyvm</span><span style="color: #89DDFF">"</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> :id</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">--name</span><span style="color: #89DDFF">"</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">web01</span><span style="color: #89DDFF">"</span><span style="color: #EEFFFF">]</span></span> <span class="line"><span style="color: #EEFFFF"> end</span></span> <span class="line"><span style="color: #EEFFFF"> end</span></span> <span class="line"><span style="color: #EEFFFF"># Deploy WebServer02</span></span> <span class="line"><span style="color: #EEFFFF"> config</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">vm</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">define </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">web02</span><span style="color: #89DDFF">"</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF; font-style: italic">do</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">|</span><span style="color: #EEFFFF">web02</span><span style="color: #89DDFF">|</span></span> <span class="line"><span style="color: #EEFFFF"> web02</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">vm</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">box </span><span style="color: #89DDFF">=</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">generic/rhel9</span><span style="color: #89DDFF">"</span></span> <span class="line"><span style="color: #EEFFFF"> config</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">vm</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">provision :shell</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> </span><span style="color: #FFCB6B">path</span><span style="color: #89DDFF">:</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">web02config.sh</span><span style="color: #89DDFF">"</span></span> <span class="line"><span style="color: #EEFFFF"> web02</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">vm</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">hostname </span><span style="color: #89DDFF">=</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">'</span><span style="color: #C3E88D">web02</span><span style="color: #89DDFF">'</span></span> <span class="line"><span style="color: #EEFFFF"> web02</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">vm</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">box_url </span><span style="color: #89DDFF">=</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">generic/rhel9</span><span style="color: #89DDFF">"</span></span> <span class="line"><span style="color: #EEFFFF"> web02</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">vm</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">network :private_network</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> </span><span style="color: #FFCB6B">ip</span><span style="color: #89DDFF">:</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">10.0.2.53</span><span style="color: #89DDFF">"</span></span> <span class="line"><span style="color: #EEFFFF"> web02</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">vm</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">provider :virtualbox </span><span style="color: #89DDFF; font-style: italic">do</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">|</span><span style="color: #EEFFFF">v</span><span style="color: #89DDFF">|</span></span> <span class="line"><span style="color: #EEFFFF"> v</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">customize [</span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">modifyvm</span><span style="color: #89DDFF">"</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> :id</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">--natdnshostresolver1</span><span style="color: #89DDFF">"</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">on</span><span style="color: #89DDFF">"</span><span style="color: #EEFFFF">]</span></span> <span class="line"><span style="color: #EEFFFF"> v</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">customize [</span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">modifyvm</span><span style="color: #89DDFF">"</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> :id</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">--memory</span><span style="color: #89DDFF">"</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> </span><span style="color: #F78C6C">1024</span><span style="color: #EEFFFF">]</span></span> <span class="line"><span style="color: #EEFFFF"> v</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">customize [</span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">modifyvm</span><span style="color: #89DDFF">"</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> :id</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">--name</span><span style="color: #89DDFF">"</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">web02</span><span style="color: #89DDFF">"</span><span style="color: #EEFFFF">]</span></span> <span class="line"><span style="color: #EEFFFF"> end</span></span> <span class="line"><span style="color: #EEFFFF"> end</span></span> <span class="line"><span style="color: #EEFFFF"># Deploy Database Server</span></span> <span class="line"><span style="color: #EEFFFF"> config</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">vm</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">define </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">db</span><span style="color: #89DDFF">"</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF; font-style: italic">do</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">|</span><span style="color: #EEFFFF">db</span><span style="color: #89DDFF">|</span></span> <span class="line"><span style="color: #EEFFFF"> db</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">vm</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">box </span><span style="color: #89DDFF">=</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">generic/rhel9</span><span style="color: #89DDFF">"</span></span> <span class="line"><span style="color: #EEFFFF"> db</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">vm</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">hostname </span><span style="color: #89DDFF">=</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">'</span><span style="color: #C3E88D">db</span><span style="color: #89DDFF">'</span></span> <span class="line"><span style="color: #EEFFFF"> db</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">vm</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">box_url </span><span style="color: #89DDFF">=</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">generic/rhel9</span><span style="color: #89DDFF">"</span></span> <span class="line"><span style="color: #EEFFFF"> db</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">vm</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">network :private_network</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> </span><span style="color: #FFCB6B">ip</span><span style="color: #89DDFF">:</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">10.0.2.54</span><span style="color: #89DDFF">"</span></span> <span class="line"><span style="color: #EEFFFF"> db</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">vm</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">provider :virtualbox </span><span style="color: #89DDFF; font-style: italic">do</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">|</span><span style="color: #EEFFFF">v</span><span style="color: #89DDFF">|</span></span> <span class="line"><span style="color: #EEFFFF"> v</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">customize [</span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">modifyvm</span><span style="color: #89DDFF">"</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> :id</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">--natdnshostresolver1</span><span style="color: #89DDFF">"</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">on</span><span style="color: #89DDFF">"</span><span style="color: #EEFFFF">]</span></span> <span class="line"><span style="color: #EEFFFF"> v</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">customize [</span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">modifyvm</span><span style="color: #89DDFF">"</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> :id</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">--memory</span><span style="color: #89DDFF">"</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> </span><span style="color: #F78C6C">1024</span><span style="color: #EEFFFF">]</span></span> <span class="line"><span style="color: #EEFFFF"> v</span><span style="color: #89DDFF">.</span><span style="color: #EEFFFF">customize [</span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">modifyvm</span><span style="color: #89DDFF">"</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> :id</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">--name</span><span style="color: #89DDFF">"</span><span style="color: #89DDFF">,</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D">db</span><span style="color: #89DDFF">"</span><span style="color: #EEFFFF">]</span></span> <span class="line"><span style="color: #EEFFFF"> end</span></span> <span class="line"><span style="color: #EEFFFF"> end</span></span> |
Define the following for our webserver config web01config.sh & web02config.sh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<span class="line"><span style="color: #546E7A; font-style: italic">#!Apache Config</span></span> <span class="line"></span> <span class="line"><span style="color: #EEFFFF">dnf install </span><span style="color: #89DDFF">--</span><span style="color: #EEFFFF">assumeyes httpd mod_ssl</span></span> <span class="line"><span style="color: #EEFFFF">#setenforce </span><span style="color: #F78C6C">0</span></span> <span class="line"><span style="color: #EEFFFF">systemctl start httpd</span></span> <span class="line"><span style="color: #EEFFFF">systemctl enable httpd</span></span> <span class="line"><span style="color: #EEFFFF">firewall</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">cmd </span><span style="color: #89DDFF">--</span><span style="color: #EEFFFF">permanent </span><span style="color: #89DDFF">--</span><span style="color: #EEFFFF">add</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">service</span><span style="color: #89DDFF">=</span><span style="color: #EEFFFF">http </span><span style="color: #89DDFF">--</span><span style="color: #EEFFFF">add</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">service</span><span style="color: #89DDFF">=</span><span style="color: #EEFFFF">https</span></span> <span class="line"><span style="color: #EEFFFF">firewall</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">cmd </span><span style="color: #89DDFF">--</span><span style="color: #EEFFFF">reload</span></span> <span class="line"><span style="color: #EEFFFF">iptables</span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">A INPUT </span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">m state </span><span style="color: #89DDFF">--</span><span style="color: #EEFFFF">state NEW </span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">m tcp </span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">p tcp </span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">s </span><span style="color: #F78C6C">192.168</span><span style="color: #89DDFF">.</span><span style="color: #F78C6C">1.0</span><span style="color: #89DDFF">/</span><span style="color: #F78C6C">24</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">--</span><span style="color: #EEFFFF">dport </span><span style="color: #F78C6C">80</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">j ACCEPT</span></span> <span class="line"><span style="color: #EEFFFF">iptables </span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">A INPUT </span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">m state </span><span style="color: #89DDFF">--</span><span style="color: #EEFFFF">state NEW </span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">m tcp </span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">p tcp </span><span style="color: #89DDFF">--</span><span style="color: #EEFFFF">dport </span><span style="color: #F78C6C">80</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">j ACCEPT</span></span> <span class="line"><span style="color: #EEFFFF">iptables </span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">A INPUT </span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">m state </span><span style="color: #89DDFF">--</span><span style="color: #EEFFFF">state NEW </span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">m tcp </span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">p tcp </span><span style="color: #89DDFF">--</span><span style="color: #EEFFFF">dport </span><span style="color: #F78C6C">443</span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">-</span><span style="color: #EEFFFF">j ACCEPT</span></span> <span class="line"><span style="color: #EEFFFF">service iptables save</span></span> <span class="line"><span style="color: #EEFFFF">service iptables restart</span></span> <span class="line"><span style="color: #EEFFFF">echo This is my webserver $HOSTNAME </span><span style="color: #89DDFF">></span><span style="color: #EEFFFF"> </span><span style="color: #89DDFF">/</span><span style="color: #C792EA">var</span><span style="color: #EEFFFF">/www/html/index.htmlecho </span><span style="color: #89DDFF">"</span><span style="color: #C3E88D"><h1> This is a test website </h1></span><span style="color: #89DDFF">"</span><span style="color: #EEFFFF"> >/var/www/html/index.html</span></span> |
Start the virtual machines by running the following command:
Show the status of all virtual machines by running the following command:
Connect to the VM via ssh command