-
Notifications
You must be signed in to change notification settings - Fork 1
/
add_nic_windows.yml
32 lines (26 loc) · 1.03 KB
/
add_nic_windows.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
- hosts: all
vars:
ip_mask: "{{ip_addr}}/{{subnet_mask}}"
list_dns_servers: "{{dns_servers.split(',')}}"
tasks:
- name: get interface
win_shell: |
function Get-MACAddress {
param ($MacAddress)
$colItems = Get-NetAdapter
foreach ($objItem in $colItems) {
if($objItem.MacAddress -eq $MacAddress){
$objItem.Name
}
}
}
Get-MacAddress("{{mac_address|replace(":", "-")}}")
register: interface
- name: set ip settings
win_shell: |
New-NetIPAddress -InterfaceAlias "{{interface.stdout | trim}}" -IPAddress "{{ip_addr}}" -PrefixLength {{ ip_mask| ipaddr('prefix') }} -DefaultGateway {{gateway}}
Disable-NetAdapterBinding -InterfaceAlias "{{interface.stdout | trim}}" -ComponentID ms_tcpip6
register: "config_interface"
- name: set DNS settings
win_shell: |
Set-DnsClientServerAddress -InterfaceAlias "{{interface.stdout | trim}}" -ServerAddresses ("{{list_dns_servers.0}}", "{{list_dns_servers.1}}")