| Server IP : 85.214.239.14 / Your IP : 216.73.216.27 Web Server : Apache/2.4.65 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Mon Sep 30 15:36:27 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 8.2.29 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /lib/python3/dist-packages/ansible_collections/community/windows/plugins/modules/ |
Upload File : |
#!powershell
# Copyright: (c) 2019, Thomas Moore (@tmmruk) <hi@tmmr.uk>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
#AnsibleRequires -CSharpUtil Ansible.Basic
$spec = @{
options = @{
state = @{ type = "str"; choices = "enabled", "disabled", "default"; required = $true }
adapter_names = @{ type = "list"; elements = "str"; required = $false }
}
supports_check_mode = $true
}
$module = [Ansible.Basic.AnsibleModule]::Create($args, $spec)
$module.Result.reboot_required = $false
$state = $module.Params.state
$adapter_names = $module.Params.adapter_names
switch ( $state ) {
'default' { $netbiosoption = 0 }
enabled { $netbiosoption = 1 }
disabled { $netbiosoption = 2 }
}
if (-not $adapter_names) {
# Target all network adapters on the system
$get_params = @{
ClassName = 'Win32_NetworkAdapterConfiguration'
Filter = 'IPEnabled=true'
Property = @('MacAddress', 'TcpipNetbiosOptions')
}
$target_adapters_config = Get-CimInstance @get_params
}
else {
$get_params = @{
Class = 'Win32_NetworkAdapter'
Filter = ($adapter_names | ForEach-Object -Process { "NetConnectionId='$_'" }) -join " OR "
KeyOnly = $true
}
$target_adapters_config = Get-CimInstance @get_params | Get-CimAssociatedInstance -ResultClass 'Win32_NetworkAdapterConfiguration'
if (($target_adapters_config | Measure-Object).Count -ne $adapter_names.Count) {
$module.FailJson("Not all of the target adapter names could be found on the system. No configuration changes have been made. $adapter_names")
}
}
foreach ($adapter in $target_adapters_config) {
if ($adapter.TcpipNetbiosOptions -ne $netbiosoption) {
if (-not $module.CheckMode) {
$result = Invoke-CimMethod -InputObject $adapter -MethodName SetTcpipNetbios -Arguments @{TcpipNetbiosOptions = $netbiosoption }
switch ( $result.ReturnValue ) {
0 { <# Success no reboot required #> }
1 { $module.Result.reboot_required = $true }
100 {
$msg = "DHCP not enabled on adapter $($adapter.MacAddress). Unable to set default. Try using disabled or enabled options instead."
$module.Warn($msg)
}
default {
$msg = "An error occurred while setting TcpipNetbios options on adapter $($adapter.MacAddress). Return code $($result.ReturnValue)."
$module.FailJson($msg)
}
}
}
$module.Result.changed = $true
}
}
$module.ExitJson()