IIS Site Root Path Swap
Description
This playbook automates changing the root path of an existing IIS website on Windows servers. It retrieves the current site configuration, updates the physical path to a new subdirectory within the site's folder structure, and verifies the change. This is commonly used for deployment scenarios where you need to switch between different versions of an application (e.g., switching from 'current' to 'new' or between versioned folders).
Credentials
- sys_ansible_iis (IIS management service account)
Input
| Variable | Description | Example |
|---|---|---|
target |
Target Windows server(s) where the site exists | srviisf3pr* |
site_name |
Name of the IIS site (exact IIS site name) | D09.Site |
site_version |
Subdirectory to switch the site's physical path to | v2.0 / current / blue |
Output (Ansible facts)
| Variable | Description |
|---|---|
iis_creds |
IIS service account credentials from Passwordstate |
current_site_info |
Current IIS site configuration before the change |
website |
Result of the website root path update operation |
new_site_info |
Updated IIS site configuration after the change |
Process Flow
- Retrieve Credentials: Gets IIS service account credentials from Passwordstate.
- Set Site Name: Stores
site_nameasiis_appName(no prefix logic in current playbook). - Get Current Configuration: Gathers existing site info (including current
physical_path). - Construct New Path: Builds new path:
M:\Sites\{iis_appName}\{site_version}. - Update Website: Starts site (if stopped) and points it to the new directory.
- Verify Change: Retrieves updated site info to confirm the swap.
Path Structure
The playbook follows this path convention:
Examples:
- Original: M:\Sites\D09.Site\current\
- Updated: M:\Sites\D09.Site\v2.0\
Use Cases
- Application Deployment: Switch between different versions of an application
- Blue-Green Deployment: Swap between 'blue' and 'green' deployment folders
- Rollback Operations: Quickly revert to a previous version by changing the root path
- Staging to Production: Point production site to newly deployed code
Prerequisites
- Target directory must exist on the file system before running
- IIS service account must have appropriate permissions to the new path
- Site must already exist in IIS (this playbook only changes the root path)
- Application files must be present in the target directory
Example Usage
# Switch myapp site to version 2.0 folder
target: "srviisf3pr01.gentgrp.gent.be"
site_name: "D09.Site"
site_version: "v2.0"
This would change the site from M:\Sites\D09.Site\current\ to M:\Sites\D09.Site\v2.0\
Security Notes
- Uses Passwordstate for secure credential management
- Credentials are marked with
no_log: trueto prevent exposure in logs - Service account has minimal required permissions for IIS management