From 196f4d09dc5c8c6b52423da6ef791a9b56451cb0 Mon Sep 17 00:00:00 2001 From: ogrechko Date: Wed, 3 Dec 2025 05:30:53 +0000 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20test-playbooks/win=5Fdns=5Fps.yml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test-playbooks/win_dns_ps.yml | 40 ++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/test-playbooks/win_dns_ps.yml b/test-playbooks/win_dns_ps.yml index 3c4a79e..c9161f7 100644 --- a/test-playbooks/win_dns_ps.yml +++ b/test-playbooks/win_dns_ps.yml @@ -1,10 +1,34 @@ --- -- name: win_powershell_exec - hosts: all +- name: Check and Configure DNS on Windows + hosts: windows + gather_facts: no + + vars: + ansible_connection: winrm + ansible_winrm_server_cert_validation: ignore + ansible_shell_type: powershell + ansible_remote_tmp: C:\Windows\Temp + tasks: - - name: check DNS - win_shell: | - Get-DnsClientServerAddress -InterfaceIndex (Get-NetAdapter|where Status -eq "Up").ifindex -ErrorAction SilentlyContinue - register: command_output - - name: command output - ansible.builtin.debug: \ No newline at end of file + - name: Get all active network adapters + ansible.windows.win_shell: | + Get-NetAdapter | Where-Object { $_.Status -eq "Up" } | Select-Object Name, InterfaceIndex, Status + register: adapters + + - name: Display active adapters + ansible.builtin.debug: + var: adapters.stdout_lines + + - name: Check DNS for each active adapter + ansible.windows.win_shell: | + $adapters = Get-NetAdapter | Where-Object { $_.Status -eq "Up" } + foreach ($adapter in $adapters) { + Write-Output "=== Adapter: $($adapter.Name) ===" + Get-DnsClientServerAddress -InterfaceIndex $adapter.InterfaceIndex + Write-Output "" + } + register: dns_info + + - name: Show DNS information + ansible.builtin.debug: + var: dns_info.stdout_lines \ No newline at end of file