| 1 |
# Test code for win_netbios module |
| 2 |
# Copyright: (c) 2019, Thomas Moore <[email protected]> |
| 3 |
|
| 4 |
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 5 |
# |
| 6 |
# Ansible is free software: you can redistribute it and/or modify |
| 7 |
# it under the terms of the GNU General Public License as published by |
| 8 |
# the Free Software Foundation, either version 3 of the License, or |
| 9 |
# (at your option) any later version. |
| 10 |
# |
| 11 |
# Ansible is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
# GNU General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU General Public License |
| 17 |
# along with Ansible. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
|
| 19 |
- set_fact: |
| 20 |
get_netbios_script: | |
| 21 |
$adapter = Get-CimInstance -ClassName Win32_NetworkAdapter -Filter "NetConnectionID='{{ network_adapter_name }}'" |
| 22 |
$config = Get-CimInstance -ClassName Win32_NetworkAdapterConfiguration -Filter "Index=$($adapter.DeviceID)" |
| 23 |
$config.TcpipNetbiosOptions |
| 24 |
|
| 25 |
- name: disable netbios single adapter (check mode) |
| 26 |
win_netbios: |
| 27 |
adapter_names: '{{ network_adapter_name }}' |
| 28 |
state: disabled |
| 29 |
register: set_single_check |
| 30 |
check_mode: yes |
| 31 |
|
| 32 |
- name: get result of disable a single adapter test (check mode) |
| 33 |
ansible.windows.win_shell: '{{ get_netbios_script }}' |
| 34 |
changed_when: no |
| 35 |
register: set_single_actual_check |
| 36 |
|
| 37 |
- name: assert disable a single adapter (check mode) |
| 38 |
assert: |
| 39 |
that: |
| 40 |
- set_single_check is changed |
| 41 |
- set_single_actual_check.stdout_lines == ["0"] |
| 42 |
|
| 43 |
- name: disable netbios single adapter |
| 44 |
win_netbios: |
| 45 |
adapter_names: '{{ network_adapter_name }}' |
| 46 |
state: disabled |
| 47 |
register: set_single |
| 48 |
|
| 49 |
- name: get result of disable a single adapter test |
| 50 |
ansible.windows.win_shell: '{{ get_netbios_script }}' |
| 51 |
changed_when: no |
| 52 |
register: set_single_actual |
| 53 |
|
| 54 |
- name: assert disable a single adapter |
| 55 |
assert: |
| 56 |
that: |
| 57 |
- set_single_check is changed |
| 58 |
- set_single_actual.stdout_lines == ["2"] |
| 59 |
|
| 60 |
- name: fail with invalid network adapter name |
| 61 |
win_netbios: |
| 62 |
state: disabled |
| 63 |
adapter_names: |
| 64 |
- FakeAdapterName |
| 65 |
register: invalid_adapter |
| 66 |
failed_when: invalid_adapter.msg != "Not all of the target adapter names could be found on the system. No configuration changes have been made. FakeAdapterName" |
| 67 |
|
| 68 |
- name: disable netbios all adapters (check mode) |
| 69 |
win_netbios: |
| 70 |
state: disabled |
| 71 |
check_mode: yes |
| 72 |
register: disable_check |
| 73 |
|
| 74 |
- name: assert disable netbios (check mode) |
| 75 |
assert: |
| 76 |
that: |
| 77 |
- disable_check.changed |
| 78 |
|
| 79 |
- name: disable netbios all adapters |
| 80 |
win_netbios: |
| 81 |
state: disabled |
| 82 |
register: netbios_disable |
| 83 |
|
| 84 |
- name: assert netbios disabled |
| 85 |
assert: |
| 86 |
that: |
| 87 |
- netbios_disable.changed |
| 88 |
|
| 89 |
- name: test disable idempotence |
| 90 |
win_netbios: |
| 91 |
state: disabled |
| 92 |
register: netbios_disable |
| 93 |
|
| 94 |
- name: test disable idempotence |
| 95 |
assert: |
| 96 |
that: |
| 97 |
- not netbios_disable.changed |
| 98 |
|
| 99 |
- name: enable netbios all adapters (check mode) |
| 100 |
win_netbios: |
| 101 |
state: enabled |
| 102 |
check_mode: yes |
| 103 |
register: enable_check |
| 104 |
|
| 105 |
- name: assert enable netbios all adapters (check mode) |
| 106 |
assert: |
| 107 |
that: |
| 108 |
- enable_check.changed |
| 109 |
|
| 110 |
- name: enable netbios all adapters |
| 111 |
win_netbios: |
| 112 |
state: enabled |
| 113 |
register: netbios_enable |
| 114 |
|
| 115 |
- name: assert netbios enabled |
| 116 |
assert: |
| 117 |
that: |
| 118 |
- netbios_enable.changed |
| 119 |
|
| 120 |
- name: test enable idempotence |
| 121 |
win_netbios: |
| 122 |
state: enabled |
| 123 |
register: netbios_enable |
| 124 |
|
| 125 |
- name: assert enable idempotence |
| 126 |
assert: |
| 127 |
that: |
| 128 |
- not netbios_enable.changed |
| 129 |
|
| 130 |
- name: default netbios all adapters (check mode) |
| 131 |
win_netbios: |
| 132 |
state: default |
| 133 |
check_mode: yes |
| 134 |
register: default_check |
| 135 |
|
| 136 |
- name: assert default netbios (check mode) |
| 137 |
assert: |
| 138 |
that: |
| 139 |
- default_check.changed |
| 140 |
|
| 141 |
- name: default netbios all adapters |
| 142 |
win_netbios: |
| 143 |
state: default |
| 144 |
register: default_enable |
| 145 |
|
| 146 |
- name: assert netbios default all adapters |
| 147 |
assert: |
| 148 |
that: |
| 149 |
- default_enable.changed |
| 150 |
|
| 151 |
- name: test default idempotence |
| 152 |
win_netbios: |
| 153 |
state: default |
| 154 |
register: netbios_default |
| 155 |
|
| 156 |
- name: assert default idempotence |
| 157 |
assert: |
| 158 |
that: |
| 159 |
- not netbios_default.changed |