43 lines
1.4 KiB
YAML
43 lines
1.4 KiB
YAML
---
|
|
# 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 }}"
|