Created
July 20, 2023 15:32
-
-
Save timothywarner/aed52a5429e3eb4cd56452a0289cf880 to your computer and use it in GitHub Desktop.
Ansible playbook: Install Hyper-V and create a VM on Windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: Install Hyper-V role and create VM on mem01 | |
hosts: mem01 | |
gather_facts: no | |
tasks: | |
- name: Install Hyper-V with GUI and PowerShell tools | |
win_feature: | |
name: | |
- Hyper-V | |
- RSAT-Hyper-V-Tools | |
- Hyper-V-PowerShell | |
state: present | |
include_sub_features: yes | |
include_management_tools: yes | |
register: install_result | |
- name: Reboot if necessary | |
win_reboot: | |
when: install_result.reboot_required | |
- name: Wait for WinRM to come back | |
pause: | |
seconds: 60 | |
- name: Create a Hyper-V VM | |
win_shell: | | |
New-VM -Name web01 -MemoryStartupBytes 2GB -NewVHDPath "C:\Hyper-V\web01.vhdx" -NewVHDSizeBytes 127GB -Generation 1 | |
when: install_result.changed | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment