Skip to content

Instantly share code, notes, and snippets.

@teridon
Last active January 26, 2024 14:52
Show Gist options
  • Save teridon/137550c134e8b83716b0172baa5302af to your computer and use it in GitHub Desktop.
Save teridon/137550c134e8b83716b0172baa5302af to your computer and use it in GitHub Desktop.
ansible windows change NIC advanced parameters that break the network connection
---
- name: disable some NUC NIC driver features
hosts: windows,!gs483-actb-daq*
gather_facts: yes
become: yes
tasks:
- name: Get Hardware Model
win_shell: (Get-CimInstance -ClassName Win32_ComputerSystem).Model
register: model
- debug: var=model.stdout
- name: stop if host is NOT a NUC11
meta: end_host
when: '"NUC11TNKv7" not in model.stdout'
# use scheduled task because using win_shell hangs when the network drops
# note the sched task deletes itself
# also note, you CAN set multiple parameters to the same value in one command thusly:
# -DisplayName "Selective Suspend","NS Offload" -DisplayValue "Disabled"
# However, that makes this playbook harder to edit (it's easier to delete a whole line)
- name: Disable ARP Offload via scheduled task
win_scheduled_task:
name: DisableOffload
username: SYSTEM
actions:
- path: powershell.exe
arguments: "Get-NetAdapterHardwareInfo | where {$_.Name -like 'Ethernet*'} | Set-NetAdapterAdvancedProperty -DisplayName 'ARP Offload' -DisplayValue 'Disabled'"
- path: powershell.exe
arguments: "Get-NetAdapterHardwareInfo | where {$_.Name -like 'Ethernet*'} | Set-NetAdapterAdvancedProperty -DisplayName 'Large Send Offload V2 (IPV4)' -DisplayValue 'Disabled'"
- path: powershell.exe
arguments: "Get-NetAdapterHardwareInfo | where {$_.Name -like 'Ethernet*'} | Set-NetAdapterAdvancedProperty -DisplayName 'NS Offload' -DisplayValue 'Disabled'"
- path: powershell.exe
arguments: "Get-NetAdapterHardwareInfo | where {$_.Name -like 'Ethernet*'} | Set-NetAdapterAdvancedProperty -DisplayName 'Packet Priority & VLAN' -DisplayValue 'Disabled'"
- path: powershell.exe
arguments: "Get-NetAdapterHardwareInfo | where {$_.Name -like 'Ethernet*'} | Set-NetAdapterAdvancedProperty -DisplayName 'Selective Suspend' -DisplayValue 'Disabled'"
- path: cmd.exe
arguments: /c schtasks.exe /Delete /TN "DisableOffload" /F
triggers:
- type: registration
# wait for scheduled task to start changing things
# you will lose your SSH connection
- name: pause for 15 seconds
ansible.builtin.pause:
seconds: 15
- name: reconnect
ansible.builtin.wait_for_connection:
# scheduled task should already be done but verify
- name: Wait for the scheduled task to complete
win_scheduled_task_stat:
name: DisableOffload
register: task_stat
until: (task_stat.state is defined and task_stat.state.status != "TASK_STATE_RUNNING") or (task_stat.task_exists == False)
retries: 7
delay: 5
tags: task
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment