This commit is contained in:
2026-04-29 09:52:02 -04:00
parent fe11468547
commit a096a7eaa0
4 changed files with 1333 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
---
# Quick playbook to list available Hyper-V virtual switches
# Usage: ansible-playbook playbooks/list-hyperv-switches.yml
- name: List Hyper-V Virtual Switches
hosts: hyperv
gather_facts: false
tasks:
- name: Get virtual switches
ansible.windows.win_shell: |
Get-VMSwitch | Select-Object Name, SwitchType, NetAdapterInterfaceDescription | Format-Table -AutoSize
register: switches
changed_when: false
- name: Display switches
ansible.builtin.debug:
msg: "{{ switches.stdout_lines }}"
- name: Get switches in JSON format
ansible.windows.win_shell: |
Get-VMSwitch | Select-Object Name, SwitchType | ConvertTo-Json
register: switches_json
changed_when: false
- name: Parse switches
ansible.builtin.set_fact:
switch_list: "{{ switches_json.stdout | from_json }}"
- name: Display switch names
ansible.builtin.debug:
msg:
- "========================================="
- "Available Virtual Switches:"
- "========================================="
- "{{ switch_list | map(attribute='Name') | list }}"
- ""
- "To use a switch, either:"
- "1. Pass as variable: -e vm_switch='<switch_name>'"
- "2. Update default in: /home/ptoal/Dev/inventories/toallab-inventory/group_vars/hyperv/vars.yml"
- ""
- "Current default: {{ default_vm_switch }}"