DevOps Challenge #2 - Ansible automation magic
This task requires you to use Ansible and YAML to write playbooks
Hey there, cloud wranglers! 🤠 So you've been playing with AWS and Terraform, but have you explored the wonders of Ansible yet? If not, here's your chance! In this article, we're going to set up an Apache web server on an Ubuntu machine, all automated with Ansible. Trust me, it's as cool as it sounds!
Here is the task:
## Ansible Exercise 1: Configure a Web Server
### Objective
Your task is to write an Ansible playbook that automates the following tasks on a remote Ubuntu server:
- **Step 1**: Update the package manager cache.
- **Step 2**: Install the Apache web server package (`apache2`).
- **Step 3**: Enable and start the Apache service.
- **Step 4**: Deploy a simple `index.html` file to the document root `/var/www/html/`. The HTML should display "Hello, Ansible!"
### Requirements
- The playbook should be idempotent, meaning it can be run multiple times without changing the outcome.
- The target hosts should be defined in your Ansible inventory
What You'll Need
A machine running Ubuntu (either a VM or a real server—it's all good)
Ansible installed on your control node
SSH access to your Ubuntu machine
A little bit of know-how with YAML and the command line
Automate Your Web Server Setup with Ansible: A Hands-on Exercise
Introduction
Hey there, cloud wranglers! 🤠 So you've been playing with AWS and Terraform, but have you explored the wonders of Ansible yet? If not, here's your chance! In this article, we're going to set up an Apache web server on an Ubuntu machine, all automated with Ansible. Trust me, it's as cool as it sounds!
What You'll Need
A machine running Ubuntu (either a VM or a real server—it's all good)
Ansible installed on your control node
SSH access to your Ubuntu machine
A little bit of know-how with YAML and command line
Exercise 1: Your Very Own Web Server
Objective
Alright, champ, your mission, should you choose to accept it, involves a few key steps:
Update the Ubuntu server's package manager.
Install Apache web server.
Make sure the Apache service is up and running.
Deploy a simple "Hello, Ansible!" webpage.
Steps
Step 1: Set Up Inventory
First, make sure you have the target Ubuntu host's IP address in your Ansible inventory. The inventory file often lives in /etc/ansible/hosts
.
[webserver]
192.168.1.2 ansible_ssh_user=ubuntu
Step 2: Write the Playbook
Open your favourite text editor (yeah, you can use Vim if you're old-school like that), and create a new file called web_server_setup.yml
.
Here's the playbook to achieve our mission:
---
- hosts: webserver
tasks:
- name: Update package manager cache
apt:
update_cache: yes
- name: Install Apache web server
apt:
name: apache2
- name: Enable and start Apache service
systemd:
name: apache2
enabled: yes
state: started
- name: Deploy index.html
copy:
content: "<h1>Hello, Ansible!</h1>"
dest: /var/www/html/index.html
Step 3: Run the Playbook
Navigate to /home/ubuntu/tech-vault-ansible
and execute:
ansible-playbook web_server_setup.yml
Conclusion
Boom, you did it! You should now have a running Apache web server, and if you visit the server's IP address in a web browser, you should see a lovely "Hello, Ansible!" greeting. You've just stepped into the world of automating server setups with Ansible, and trust me, it's a skill that'll make you feel like a wizard. 🧙♂️