Files
hyperv-demo/README.md
2026-04-28 22:45:25 -04:00

148 lines
4.6 KiB
Markdown

# Hyper-V Windows Server Automation
Enterprise-grade automation for Windows Server VM lifecycle management on Hyper-V using Ansible Automation Platform, GitOps, and Infrastructure as Code practices.
## Overview
This project demonstrates automated Windows Server VM management including:
- **Provisioning**: Automated VM creation using autounattend.xml
- **Configuration Management**: Day-2 operations and application deployment
- **Patch Management**: Automated Windows updates via git commits
- **CMDB Integration**: ServiceNow CMDB synchronization
- **Event-Driven Automation**: Future EDA integration
## Quick Start
### Development Environment
```bash
# Activate Ansible virtual environment
source ~/.venv/ansible/bin/activate
# Install required collections
ansible-galaxy collection install -r collections/requirements.yml
# Verify Hyper-V connectivity
ansible hyperv -m ansible.windows.win_ping
```
### Provision a New VM
```bash
# Using ansible-navigator (recommended)
ansible-navigator run playbooks/provision-vm.yml \
--execution-environment-image aap.toal.ca/ee-demo \
--extra-vars "vm_name=WEB01 vm_ip_address=192.168.1.101"
# Or with ansible-playbook
ansible-playbook playbooks/provision-vm.yml \
-e vm_name=WEB01 \
-e vm_ip_address=192.168.1.101 \
-e vm_cpu_count=4 \
-e vm_memory_gb=8
```
**See [playbooks/README-provision.md](playbooks/README-provision.md) for detailed provisioning guide**
### Manage Existing VMs
```bash
# Patch management
ansible-playbook playbooks/patch-vms.yml --limit windows_servers
# Install IIS demo application
ansible-playbook playbooks/install-iis.yml --limit web_servers
# Update CMDB
ansible-playbook playbooks/sync-cmdb.yml
```
## Project Structure
```
.
├── ansible.cfg # Ansible config → uses toallab-inventory
├── playbooks/ # Automation workflows
│ ├── provision-vm.yml # VM provisioning with autounattend
│ ├── create-autounattend-iso.yml # Helper for ISO creation
│ ├── patch-vms.yml # Windows Update automation
│ ├── install-iis.yml # IIS deployment demo
│ ├── sync-cmdb.yml # ServiceNow integration
│ └── README-provision.md # Detailed provisioning guide
├── templates/ # Jinja2 templates
│ └── autounattend.xml.j2 # Windows unattended install
├── roles/ # Custom roles (future)
└── collections/
└── requirements.yml # Required collections
```
**Inventory Location**: `/home/ptoal/Dev/inventories/toallab-inventory`
- `group_vars/hyperv/` - Hyper-V host configuration
- `group_vars/windows_servers/` - Windows Server defaults
- `host_vars/hyperv1.lan.toal.ca/` - Hypervisor settings
## Prerequisites
- Ansible Automation Platform 2.x
- Hyper-V Server or Windows Server with Hyper-V role
- Windows Server ISO images
- ServiceNow instance (for CMDB integration)
- Active Directory domain (for authentication)
## Key Features
### VM Provisioning
- **Automated Installation**: Uses autounattend.xml for unattended Windows setup
- **Flexible Configuration**: CPU, memory, disk size configurable via variables
- **Network Setup**: Static IP or DHCP configuration
- **WinRM Ready**: Automatically configured for Ansible management
### Idempotent Operations
- All playbooks can be run multiple times safely
- Check mode support for validation
- Proper state management
### AAP Integration
- Job template surveys for user-friendly VM creation
- Webhook support for GitOps workflows
- Credential management for secure operations
## Hypervisor
**Host**: hyperv1.lan.toal.ca (192.168.1.182)
**Connection**: WinRM over HTTP (NTLM auth)
**Default Storage**: D:\VMs
**Default ISO Path**: D:\ISOs
## Documentation
- [CLAUDE.md](CLAUDE.md) - Architecture and development guidelines
- [playbooks/README-provision.md](playbooks/README-provision.md) - VM provisioning guide
- [templates/autounattend.xml.j2](templates/autounattend.xml.j2) - Windows unattended install template
## Common Tasks
### Provision a VM
```bash
ansible-playbook playbooks/provision-vm.yml -e vm_name=WEB01 -e vm_ip_address=192.168.1.101
```
### Add VM to Inventory
```bash
# Edit /home/ptoal/Dev/inventories/toallab-inventory/static.yml
# Add under web_servers/app_servers/db_servers:
WEB01:
ansible_host: 192.168.1.101
```
### Configure VM
```bash
ansible-playbook playbooks/install-iis.yml --limit WEB01
```
### Patch VMs
```bash
ansible-playbook playbooks/patch-vms.yml --limit windows_servers
```