0% found this document useful (0 votes)
6 views5 pages

Experiment-7 (4)

This document outlines an experiment on using Ansible for configuration management, detailing the installation of VirtualBox and Vagrant, and the creation of a Linux VM. It covers the basics of Ansible, including its components like Inventory, Playbooks, and Modules, and provides step-by-step instructions for setting up a web server using a Playbook. The experiment concludes with the successful deployment of a web server and verification of its functionality.

Uploaded by

Manoj Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views5 pages

Experiment-7 (4)

This document outlines an experiment on using Ansible for configuration management, detailing the installation of VirtualBox and Vagrant, and the creation of a Linux VM. It covers the basics of Ansible, including its components like Inventory, Playbooks, and Modules, and provides step-by-step instructions for setting up a web server using a Playbook. The experiment concludes with the successful deployment of a web server and verification of its functionality.

Uploaded by

Manoj Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Ability Enhancement Course-DevOps BCSL657D

Experiment-7
Configuration Management with Ansible: Basics of Ansible:
Inventory, Playbooks, and Modules, Automating Server
Configurations with Playbooks, Hands-On: Writing and Running a
Basic Playbook.
Objective:
To understand the basics of Ansible — Inventory, Playbooks, and Modules — and use
Playbooks to automate server configurations. This includes setting up a Linux environment
using Vagrant and VirtualBox, installed via Chocolatey.

What is Ansible?
Ansible is an open-source configuration management and automation tool. It helps system
administrators and DevOps engineers to automate:

Software installation and configuration

Server provisioning

Application deployment

System updates and patching

Key Features of Ansible:

 Agentless: No agent is needed on the target machine. It uses SSH to communicate.


 Simple syntax: Uses YAML to define tasks in Playbooks.
 Idempotent: Running the same playbook multiple times won’t cause unintended changes.
 Modular: Uses built-in modules like apt, yum, copy, service, etc.

Ansible Components:

Component Description

Inventory List of target machines to automate

Modules Reusable scripts used to perform actions

Playbook YAML file that contains tasks to be executed

Task A single unit of work to be executed on a host

Dept. of CSE, KIT, Tiptur 2024-25 1


Ability Enhancement Course-DevOps BCSL657D

Part 1: Setting Up the Environment on Windows Using


Chocolatey
 Step 1: Install Chocolatey

Open PowerShell as Administrator and run:

Set-ExecutionPolicy Bypass -Scope Process -Force; `


[System.Net.ServicePointManager]::SecurityProtocol =
[System.Net.ServicePointManager]::SecurityProtocol -bor 3072; `
iex ((New-Object
System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

Close and reopen PowerShell after installation.

 Step 2: Install VirtualBox and Vagrant via Chocolatey

choco install virtualbox -y

choco install vagrant -y

Part 2: Create and Configure a Linux VM using Vagrant


 Step 3: Create a Project Directory

mkdir ansible-vm

cd ansible-vm

 Step 4: Initialize a Vagrant Project

vagrant init ubuntu/bionic64

This creates a Vagrantfile.

 Step 5: Edit the Vagrantfile

Update the file to look like:

Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/bionic64"
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.provider "virtualbox" do |vb|
vb.memory = "2048"
vb.cpus = 2
end
end

 Step 6: Start the Virtual Machine

vagrant up

Dept. of CSE, KIT, Tiptur 2024-25 2


Ability Enhancement Course-DevOps BCSL657D

 Step 7: SSH into the VM

vagrant ssh

Part 3: Install Ansible inside the Linux VM


Once inside the VM:

sudo apt update

sudo apt install ansible -y

Verify:

ansible --version

Part 4: Write and Run Your First Ansible Playbook


 Step 8: Create Inventory File

Inside the VM, create inventory.ini:

[web]

127.0.0.1 ansible_connection=local

 Step 9: Create a Playbook

Create setup_webserver.yml:
---
- name: Setup Apache Web Server
hosts: web
become: yes
tasks:
- name: Install Apache
apt:
name: apache2
state: present
update_cache: yes
- name: Enable and start Apache
service:
name: apache2
state: started
enabled: yes
- name: Deploy custom HTML page
copy:
content: "<h1>Welcome to Ansible Web Server!</h1>"
dest: /var/www/html/index.html

 Step 10: Run the Playbook


ansible-playbook -i inventory.ini setup_webserver.yml

Dept. of CSE, KIT, Tiptur 2024-25 3


Ability Enhancement Course-DevOps BCSL657D

Part 5: Verify the Web Server


✅ Check Web Server from inside VM:

curl http://localhost

Expected output:

<h1>Welcome to Ansible Web Server!</h1>

Run the web server in browser using: http://localhost:8080 and you can see the below output.

Dept. of CSE, KIT, Tiptur 2024-25 4


Ability Enhancement Course-DevOps BCSL657D

Conclusion:
In this experiment, you have:

Installed VirtualBox and Vagrant using Chocolatey

Created a Linux VM using Vagrant

Installed Ansible and learned its core components

Wrote and executed a basic Ansible Playbook

Deployed a simple web server automatically

Dept. of CSE, KIT, Tiptur 2024-25 5

You might also like