This repository contains an Ansible playbook that automates the installation and configuration of Nginx on a Linux-based virtual machine (VM) running in VMware Workstation or VMware Player on a Windows laptop.
Before you start, make sure you have the following installed on your Windows laptop:
- VMware Workstation/Player: To run the VM.
- A Linux-based VM: Running Ubuntu, Debian, CentOS, or a similar distribution.
- Ansible: Installed on your local machine (Windows laptop or within the VM). You can use Windows Subsystem for Linux (WSL) to run Ansible if you're on Windows.
- SSH Access: Ensure that you can SSH into your VM from your Windows laptop.
- Sudo Access: The user running the Ansible playbook must have sudo privileges on the VM.
- Install VMware Workstation/Player: Follow the installation instructions from the official VMware website.
- Create or Import a VM: Set up a Linux-based VM in VMware Workstation/Player.
- Set Up SSH Access: Make sure you can SSH into your VM using a tool like PuTTY or the command line.
Create an inventory file that lists your VM's IP address and SSH credentials. Example inventory.ini
:
[webserver]
192.168.23.241 ansible_user=your_vm_username ansible_ssh_pass=your_vm_password ansible_become=yes ansible_become_password=your_sudo_password
Replace the placeholders with your VM's IP address, SSH username, and passwords.
Create a file called install_nginx.yml
with the following content:
---
- name: Install and start Nginx on the VM
hosts: webserver
become: yes
tasks:
- name: Update apt package manager (for Ubuntu/Debian)
apt:
update_cache: yes
when: ansible_distribution in ['Ubuntu', 'Debian']
- name: Install Nginx (for Ubuntu/Debian)
apt:
name: nginx
state: present
when: ansible_distribution in ['Ubuntu', 'Debian']
- name: Install Nginx (for CentOS/RHEL)
yum:
name: nginx
state: present
when: ansible_distribution in ['CentOS', 'RedHat']
- name: Ensure Nginx is running
service:
name: nginx
state: started
Run the Ansible playbook to install Nginx on your VM:
ansible-playbook -i inventory.ini install_nginx.yml
Ansible will connect to your VM, install Nginx, and ensure the service is running.
After running the playbook, verify that Nginx is installed and running:
-
Check Nginx Status:
- SSH into your VM and run: `systemctl status nginx`.
- You should see that Nginx is active and running.
-
Access Nginx in Your Browser:
- Open a web browser on your Windows laptop.
- Navigate to `http://192.168.23.241\` (replace with your VM's IP).
- You should see the Nginx default welcome page.
- SSH Issues: Ensure that your VM is reachable over SSH and that the correct credentials are provided.
- Sudo Privileges: Make sure the Ansible user has the necessary sudo privileges on the VM.
- Firewall: If you can't access Nginx from your browser, check if there's a firewall blocking HTTP traffic on port 80.
If you encounter any issues or have suggestions for improvements, feel free to open an issue or submit a pull request. Contributions are always welcome!
This project is licensed under the MIT License. See the LICENSE
file for more details.