Spent a good few hours finding the answer to the same question :) Hope below helps:

- name: Set up static IP address
  win_shell: "Get-NetIpAddress -InterfaceAlias 'Ethernet' | New-NetIpAddress -IpAddress 192.168.1.120 -PrefixLength 24 -DefaultGateway 192.168.1.1"
  async: 100 # Using "fire-and-forget" asynchronous execution for this task, otherwise it will always fail and timeout
  poll: 0

- name: Change ansible's ip address for each host
  set_fact:
    ansible_host: "192.168.1.120"

- name: Wait for the hosts network interface to come back up
  local_action:
    module: wait_for
    host: "{{ ansible_host }}"
    port: 5985
    delay: 10
    state: started
  register: wait_result

- name: Create a test folder to celebrate success
  win_file:
    path: C:\itworks
    state: directory
Answer from fairgod on Stack Overflow
🌐
Ansible
docs.ansible.com › ansible › latest › collections › community › windows › win_net_adapter_feature_module.html
community.windows.win_net_adapter_feature module – Enable or disable certain network adapters. — Ansible Community Documentation
To install it, use: ansible-galaxy collection install community.windows. To use it in a playbook, specify: community.windows.win_net_adapter_feature. ... Enable or disable some network components of a certain network adapter or all the network adapters.
🌐
Ansible
docs.ansible.com › ansible › latest › collections › ansible › windows › win_dns_client_module.html
ansible.windows.win_dns_client module – Configures DNS lookup on Windows hosts — Ansible Community Documentation
- name: Set a single address on the adapter named Ethernet ansible.windows.win_dns_client: adapter_names: Ethernet dns_servers: 192.168.34.5 - name: Set multiple lookup addresses on all visible adapters (usually physical adapters that are in the Up state), with debug logging to a file ansible.windows.win_dns_client: adapter_names: '*' dns_servers: - 192.168.34.5 - 192.168.34.6 suffix_search_list: - "corp.contoso.com" - "na.corp.contoso.com" log_path: C:\dns_log.txt - name: Set IPv6 DNS servers on the adapter named Ethernet ansible.windows.win_dns_client: adapter_names: Ethernet dns_servers: - '2001:db8::2' - '2001:db8::3' - name: Configure all adapters whose names begin with Ethernet to use DHCP-assigned DNS values ansible.windows.win_dns_client: adapter_names: 'Ethernet*' dns_servers: []
Discussions

Windows Machines with multiple Ethernet Adapters
ISSUE TYPE Bug Report COMPONENT NAME [windows] setup module ANSIBLE VERSION ansible 2.1.0.0 CONFIGURATION Default OS / ENVIRONMENT Windows hosts with one adapter and with multiple SUMMARY When we t... More on github.com
🌐 github.com
16
August 9, 2016
Windows VM: Adding new Network Interface and assigning it an IP address
A Subreddit dedicated to fostering ... Galaxy, ansible-lint, Molecule, etc. ... We have a windows template, and a deployment playbook that will deploy and set everything just fine, including the IP address of the NIC. I have some machines I need to create which I can create from our template, but then I'd like to add a second NIC and assign in an ip adress. ... I have a role which uses the vmware_guest_network ... More on reddit.com
🌐 r/ansible
8
6
November 14, 2022
Those of you using Ansible to manage Windows systems, how are things and what are you using it for?
At my last company we built a series of playbooks that do the following: Take a ServiceNow request for a server build Deploy an AWS, Azure, or VMware instance as W12R2, W16, W19, RHEL7 (99% stock image) Perform OS-specific configuration tasks like domain join, agent installs, log forwarding, security tweaks, etc dependant on a lot of parameters like what network, continent, language, etc it was supposed to be deployed with. Perform optional app-specific tasks we had automated (like installing a DB engine) Then every 8 hours forever after it would re-run those scripts to apply updates/changes to our baseline. So if we had a new agent we would do a bunch of testing then update the main playbook and next auto-run it would install globally. It took a lot of work to get there but after that the environment ran itself. People would request servers and if the options they chose were fairly risk-free it would auto-deploy, auto-configure, grant them login access, then send them an instruction email for them to get started. Risky options required manual approval, then it would auto-build. It was fairly reliable too. More on reddit.com
🌐 r/sysadmin
33
62
November 15, 2023
Ansible for setting up a fresh WinServer
If you are using vmware + ansible you can do it full windows/linux deployment from template including setting a hostname and configuring network interfaces. For other virtualisation ansible modules does not exsit or are not so good as for vmware. https://docs.ansible.com/ansible/latest/collections/community/vmware/vmware_guest_module.html More on reddit.com
🌐 r/ansible
7
2
June 4, 2024
Top answer
1 of 3
9

Spent a good few hours finding the answer to the same question :) Hope below helps:

- name: Set up static IP address
  win_shell: "Get-NetIpAddress -InterfaceAlias 'Ethernet' | New-NetIpAddress -IpAddress 192.168.1.120 -PrefixLength 24 -DefaultGateway 192.168.1.1"
  async: 100 # Using "fire-and-forget" asynchronous execution for this task, otherwise it will always fail and timeout
  poll: 0

- name: Change ansible's ip address for each host
  set_fact:
    ansible_host: "192.168.1.120"

- name: Wait for the hosts network interface to come back up
  local_action:
    module: wait_for
    host: "{{ ansible_host }}"
    port: 5985
    delay: 10
    state: started
  register: wait_result

- name: Create a test folder to celebrate success
  win_file:
    path: C:\itworks
    state: directory
2 of 3
0

This is too long for a comment so adding it here. Based on @fairgod's answer, but I was having issues with accidentally creating multiple redundant ip addresses in some contexts, so adding a step to first remove the ip and then re-add it can be useful.

- name: Set up static IP address
  ansible.windows.win_shell: |
    $addr = Get-NetIpAddress -IpAddress {{ ansible_host }};
    $addr | Remove-NetIpAddress -AsJob;
    $addr | New-NetIpAddress -IpAddress {{ new_ip_address }} -PrefixLength {{ new_prefix_length }}
  async: 100 # Using "fire-and-forget" asynchronous execution for this task, otherwise it will always fail and timeout
  poll: 0

Another method is to use netsh instead of the powershell utils, which continue to give me trouble. E.g.

    - name: Set up static IP address
      ansible.windows.win_shell: netsh interface ipv4 set address name="Ethernet" static {{ new_ip_address }} {{ new_prefix_mask }} {{ new_default_gateway }}
      async: 100 # Using "fire-and-forget" asynchronous execution for this task, otherwise it will always fail and timeout
      poll: 0
🌐
OneUptime
oneuptime.com › home › blog › how to use ansible to configure windows network settings
How to Use Ansible to Configure Windows Network Settings
February 21, 2026 - # playbook-network-profile.yml # Sets the network profile for server connections - name: Configure network profiles hosts: windows tasks: - name: Set network profile to Private ansible.windows.win_shell: | # Get all connected network adapters $profiles = Get-NetConnectionProfile foreach ($profile in $profiles) { if ($profile.NetworkCategory -ne "DomainAuthenticated") { Set-NetConnectionProfile ` -InterfaceIndex $profile.InterfaceIndex ` -NetworkCategory Private } } Get-NetConnectionProfile | Select-Object Name, NetworkCategory | ConvertTo-Json register: profile_result - name: Display network profiles ansible.builtin.debug: msg: "{{ profile_result.stdout | from_json }}"
🌐
Ansible
docs.ansible.com › ansible › latest › os_guide › intro_windows.html
Managing Windows hosts with Ansible — Ansible Community Documentation
Historically Ansible used Windows Remote Management (WinRM) as the connection protocol to manage Windows nodes. The psrp and winrm connection plugins both operate over WinRM and can be used as the connection plugin for Windows nodes. The psrp connection plugin is a newer connection plugin that offers a few benefits over the winrm connection plugin, for example: ... See Windows Remote Management for more information on how WinRM is configured and how to use the psrp and winrm connection plugins in Ansible.
🌐
Argon Systems
argonsys.com › home › kb articles › ansible to manage windows servers – step by step
Ansible to Manage Windows Servers - Step by Step - Argon Systems
September 20, 2025 - How to manage Windows Servers using Ansible. Deploy a Ansible controlling node on CentOS 7, and configure Windows Server 2016 for management. Create Ansible playbook examples with custom Powershell Ansible modules.
🌐
Ansible
docs.ansible.com › ansible › latest › network › index.html
Ansible for Network Automation — Ansible Community Documentation
Ansible Network modules extend the benefits of simple, powerful, agentless automation to network administrators and teams. Ansible Network modules can configure your network stack, test and validate existing network state, and discover and correct network configuration drift.
Find elsewhere
🌐
Ansible
docs.ansible.com › projects › ansible › latest › collections › community › windows › win_netbios_module.html
community.windows.win_netbios module – Manage NetBIOS over TCP/IP settings on Windows. — Ansible Community Documentation
To install it, use: ansible-galaxy collection install community.windows. To use it in a playbook, specify: community.windows.win_netbios. Enables or disables NetBIOS on Windows network adapters.
🌐
GitHub
github.com › ansible › ansible › issues › 17014
Windows Machines with multiple Ethernet Adapters · Issue #17014 · ansible/ansible
August 9, 2016 - ansible 2.1.0.0 · Default · Windows hosts with one adapter and with multiple · When we try templating some configuration file on Windows Servers which have different count (more then one) of Ethernet adapters we cannot use hosts fact like on Linux hosts. In Linux we have, and it perfect: ansible_default_ipv4['address'] In Windows we have: ansible_ip_addresses ·
Author   westsouthnight
🌐
RDR-IT
rdr-it.com › tutorials › softwares › ansible › ansible: installation, configuration and use with windows and linux
Ansible: installation, configuration and use with Windows and Linux - RDR-IT
July 14, 2021 - By default, Ansible tries to connect to computers with the SSH protocol, which is good for the Ubuntu server, on the other hand for our Windows group, we have to tell Ansible to use WinRM. The management of variables can be done in several ways: ... I’ll show you both. Personally, I prefer the second solution, because the hosts file quickly becomes unreadable. The first solution to configure the variables is directly in the hosts file by adding the variables in INI format.
🌐
Red Hat
redhat.com › sysadmin › configure-network-ansible-roles
How to configure network settings with Ansible system roles
November 24, 2025 - Each connection has a name or ID that identifies it. To display a list of all connections, you can use: ... Using the nmcli utility, you can add network connections and assign IPv4 or IPv6 addresses to create network connections.
🌐
Ansible
docs.ansible.com › ansible › 7 › os_guide › windows_setup.html
Setting up a Windows Host — Ansible Documentation
June 26, 2023 - ... Add your public keys to an authorized_key file in the .ssh folder of the user’s profile directory. Configure the SSH service using the sshd_config file. When using SSH key authentication with Ansible, the remote session will not have access to user credentials and will fail when attempting ...
🌐
GitHub
github.com › ome › ansible-role-network
GitHub - ome/ansible-role-network: Set up network interfaces with Ansible · GitHub
NB ONBOOT=yes is set by default, and is not configurable. # Simple network - hosts: localhost roles: - role: ome.network network_ifaces: - device: eth0 ip: 192.168.1.1 netmask: 255.255.255.0 type: ethernet gateway: 192.168.1.254 dns1: 8.8.4.4 dns2: 8.8.8.8 network_additional_params: ipv6_autoconf: "no" # Bonded network combining eth0 and eth1 - hosts: localhost roles: - role: ome.network network_ifaces: - device: bond0 ip: 192.168.1.1 prefix: 24 gateway: 192.168.1.254 dns1: 8.8.4.4 dns2: 8.8.8.8 bondmaster: bond0 - device: eth0 bondmaster: bond0 - device: eth1 bondmaster: bond0
Starred by 6 users
Forked by 14 users
Languages   Jinja 84.7% | Python 15.3%
🌐
Red Hat
redhat.com › en › technologies › management › ansible › automate-microsoft-windows-with-ansible
Automating Microsoft Windows with Red Hat Ansible Automation Platform
December 5, 2025 - By default, Ansible uses Secure ... machine—and the target hosts. For Windows systems, Ansible uses WinRM or OpenSSH to access remote machines from the control node....
🌐
Microsoft Learn
learn.microsoft.com › en-us › azure › developer › ansible › vm-configure-windows
Create a Windows virtual machine in Azure using Ansible | Microsoft Learn
August 30, 2021 - - name: Create Network Security Group azure_rm_securitygroup: resource_group: myResourceGroup name: networkSecurityGroup rules: - name: 'allow_rdp' protocol: Tcp destination_port_range: 3389 access: Allow priority: 1001 direction: Inbound - name: 'allow_web_traffic' protocol: Tcp destination_port_range: - 80 - 443 access: Allow priority: 1002 direction: Inbound - name: 'allow_powershell_remoting' protocol: Tcp destination_port_range: - 5985 - 5986 access: Allow priority: 1003 direction: Inbound - name: Create a network interface azure_rm_networkinterface: name: nic resource_group: myResourceGr
🌐
Ansible
docs.ansible.com › ansible › latest › os_guide › windows_winrm.html
Windows Remote Management — Ansible Community Documentation
Because the username and password are sent to the server to be used for double hop authentication, ensure that the hosts that the Windows host communicates with are not compromised and are trusted. CredSSP can be used for both local and domain accounts and also supports message encryption over HTTP. To use CredSSP authentication, the host vars are configured like so: ansible_user: Username ansible_password: Password # psrp ansible_connection: psrp ansible_psrp_auth: credssp # winrm ansible_connection: winrm ansible_winrm_transport: credssp
🌐
AnsiblePilot
ansiblepilot.com › home › articles › configuring windows hosts for ansible: step-by-step guide
Configuring Windows Hosts for Ansible: Step-by-Step Guide
November 19, 2024 - Learn how to configure Windows hosts for Ansible using basic authentication and WinRM. Follow our step-by-step guide to set up and run your first playbook.
🌐
TechBeatly
techbeatly.com › configure-your-windows-host-to-manage-by-ansible
Configure Your Windows Host to be Managed by Ansible | techbeatly
Note: If you have concerns about executing this readymade script (like the authentication it is using, the access policies etc), you can manually configure WinRM listener and the service by following WinRM setup documentation. Also make sure, ports 5985 and 5986 are open in the firewall (both OS as well as network side). Read How to open WinRM ports in the Windows firewall. That’s it, now you can access your Windows machine over WinRM and Ansible will be able to execute the playbook and tasks on your Windows machine.
🌐
Reddit
reddit.com › r/ansible › windows vm: adding new network interface and assigning it an ip address
r/ansible on Reddit: Windows VM: Adding new Network Interface and assigning it an IP address
November 14, 2022 - A Subreddit dedicated to fostering communication in the Ansible Community, includes Ansible, AWX, Ansible Galaxy, ansible-lint, Molecule, etc. ... We have a windows template, and a deployment playbook that will deploy and set everything just fine, including the IP address of the NIC. I have some machines I need to create which I can create from our template, but then I'd like to add a second NIC and assign in an ip adress. ... I have a role which uses the vmware_guest_network module.