ansible-collections / community.windows

Windows community collection for Ansible
https://galaxy.ansible.com/community/windows
GNU General Public License v3.0
205 stars 160 forks source link

Ability to retrieve dhcp reservation or lease without modification #591

Open dbond007 opened 2 weeks ago

dbond007 commented 2 weeks ago
SUMMARY

I would like to be able to retrieve details about a reservation, specifically if its present, without modifying it. Currently if using

- name: Locate the dhcp assigned ip address in the dhcp server
  community.windows.win_dhcp_lease:
    mac: "{{ find_mac }}"
  register: dhcp_results
  delegate_to: "{{ dhcp_delegate }}"

it will fail if it isn't present, and will modify the current entry if it is. Changing the name of the reservation to reservation-{MAC} I want to know the details only, not make any changes. This is similar to the current feature request #498 to pull all info, but i want it for the mac address for a single lease

ISSUE TYPE
COMPONENT NAME

windows.win_dhcp_lease

ADDITIONAL INFORMATION

If only the mac is present, retrieve only, or if that's considered breaking change, as it may have been depended upon to auto (not that it creates and entry with only a mac, but if new functionality was made to create a new entry with a current free ip, then a different attribute, like lookup_mac would be needed for lookup only.

- name: Locate the dhcp assigned ip address in the dhcp server
  community.windows.win_dhcp_lease:
    lookup_mac: "{{ find_mac }}"
  register: dhcp_results
  delegate_to: "{{ dhcp_delegate }}"

Powershell to do the same would be: Get-DhcpServerv4Scope | foreach {Get-DhcpServerv4Lease -computername $env:computername -allleases -ScopeId ($_.ScopeId)} | ? clientid -match 'xx-xx-xx-xx-xx-xx'