0% found this document useful (0 votes)
4 views6 pages

Devops Lab 7

This document provides a step-by-step guide for setting up Windows Subsystem for Linux (WSL) and installing Ansible for DevOps labs. It includes instructions for creating an inventory file, testing Ansible, and running playbooks to install and manage services like NGINX and Apache. Additionally, it outlines what to include in a lab report and offers examples of basic Ansible programs.

Uploaded by

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

Devops Lab 7

This document provides a step-by-step guide for setting up Windows Subsystem for Linux (WSL) and installing Ansible for DevOps labs. It includes instructions for creating an inventory file, testing Ansible, and running playbooks to install and manage services like NGINX and Apache. Additionally, it outlines what to include in a lab report and offers examples of basic Ansible programs.

Uploaded by

Praveen Chawan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Devops Lab 7 (BCSL657D)

⬛ Option 1: Use Windows Subsystem for Linux (WSL) – ● RECOMMENDED


What’s WSL?
WSL allows you to run a full Linux terminal inside Windows without a VM. It’s
lightweight and works perfectly for Ansible labs.

Steps to Set Up WSL + Ansible

Step 1: Install WSL (Windows Subsystem for Linux)


Open PowerShell as Administrator, and run this:

powershell
CopyEdit
wsl --install
This will:
 Install Ubuntu as the default Linux distro

 Automatically enable WSL and reboot your system


● If it says “The requested operation requires elevation,” make sure you're running
PowerShell as Administrator.

Step 2: Open Ubuntu (WSL)


After installation and reboot:

1. Search for "Ubuntu" in the Start menu and open it.

2. It will prompt you to set a Linux username and password (this is separate from
your Windows account).
Now you're in a real Linux terminal inside Windows — this is where you can run:
bash
CopyEdit
sudo apt update

sudo apt install ansible -y

⬛ That will install Ansible successfully.


5⃣ Verify Ansible

bash
CopyEdit

ansible –version

You should see output like:


css
CopyEdit

ansible [core 2.13.x]

● Do NOT Run sudo apt in PowerShell

PowerShell is not a Linux terminal. Only use sudo, apt, etc., in the Ubuntu app.

⬛ Important: From now on, do all Ansible-related lab work from inside the Ubuntu
WSL terminal, not from PowerShell

STEP 1 — Create Working Directory

mkdir ~/ansible-lab

cd ~/ansible-lab

If folder already exists → OK 👍

STEP 2 — Create Inventory File

nano hosts

Paste this:

[local]

localhost ansible_connection=local

Save →

CTRL + O→ ENTER CTRL+X → ENTER

STEP 3 — Test Ansible Ping


ansible -i hosts local -m ping

Expected output:

pong

STEP 4 — Create NGINX Playbook (VERY IMPORTANT)

nano install_nginx.yml

Paste ONLY this 👇

---

- name: Install and start NGINX

hosts: local

become: yes

tasks:

- name: Install nginx

apt:

name: nginx

state: present

update_cache: yes

- name: Start nginx service

service:

name: nginx

state: started

enabled: yes

Save file.

CTRL + O→ ENTER CTRL+X → ENTER

STEP 5 — Syntax Check (Best Practice)


ansible-playbook install_nginx.yml --syntax-check

If no error → Perfect

STEP 6 — Run Playbook

ansible-playbook -i hosts install_nginx.yml

You will see :

TASK [Install nginx] ok / changed

TASK [Start nginx] ok

STEP 7 — Verify Output

curl [Link]

You should see NGINX HTML welcome page.

) ‘ ¸• ) What to Include in Your VTU Lab Report

 Objective of the experiment

 Description of Inventory, Playbooks, and Modules

 Screenshots or output of:

o hosts file

o ansible -m ping
o Playbook

o Playbook execution

o curl output

 Conclusion

Or

⭐ Program 1 — Ansible Ping (Basic Module Program)

✅ Step 1 — Create Inventory

nano hosts

[local]
localhost ansible_connection=local

✅ Step 2 — Run Ping Module


ansible -i hosts local -m ping

🎯 Output:

pong

👉 This program shows Ansible Module execution

⭐ Program 2 — Install Package using Playbook

✅ Create Playbook

nano install_apache.yml

---
- name: Install Apache Server
hosts: local
become: yes

tasks:
- name: Install apache2
apt:
name: apache2
state: present

✅ Run Playbook

ansible-playbook -i hosts install_apache.yml

👉 This program shows Configuration Management

⭐ Program 3 — Create User using Ansible

✅ Create Playbook

nano create_user.yml

---
- name: Create DevOps User
hosts: local
become: yes

tasks:
- name: Create user
user:
name: student
state: present

✅ Run

ansible-playbook -i hosts create_user.yml

note:
Delete the folder (with all files inside)
rm -rf /root/ansible-lab

You might also like