Experiment-7 (4)
Experiment-7 (4)
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:
Server provisioning
Application deployment
Ansible Components:
Component Description
mkdir ansible-vm
cd ansible-vm
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
vagrant up
vagrant ssh
Verify:
ansible --version
[web]
127.0.0.1 ansible_connection=local
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
curl http://localhost
Expected output:
Run the web server in browser using: http://localhost:8080 and you can see the below output.
Conclusion:
In this experiment, you have: