Open netsandbox opened 2 years ago
+1. This happens because the reservation is not set correctly, per the output of step 2 (HostName
is null). You can also see the name attribute passed to win_dhcp_lease.ps1 is null if you run ansible with more verbosity.
However, it is set correctly if you run step 1 twice, though weirdly it doesn't report as changed even though on the second run it actually sets the reservation name.
I think this is because win_dhcp_lease.ps1#L431 simply uses the data from the lease created earlier, which doesn't use $reservation_name. If you then run it again, you hit win_dhcp_lease.ps1#L342 which updates the lease with the reservation name. Without further investigation, I'm not sure why this second change doesn't actually report back to ansible as changed.
@tigattack I can confirm that running step 1 twice helps in the situation you described.
But as noted above, I see the most important problem with the change in step 5, because this will always change the reservation after the host has renewed the lease.
Yes, agreed. I think this is most likely because the AddressState attribute of a reservation object is being compared (win_dhcp_lease.ps1#L77) when deciding whether Ansible needs to make a change or not.
I can think of little functional need for this, but I could be missing something. Hopefully the maintainer(s) of this module can provide some insight.
I did some testing today. The problem is that in
https://github.com/ansible-collections/community.windows/blob/a45cc22674a1f4e16702622ab3b5d6b41c920396/plugins/modules/win_dhcp_lease.ps1#L342
the reservation is always updated.
And Set-DhcpServerv4Reservation
always update the reservation and set the AddressState
to InactiveReservation
.
And as Set-DhcpServerv4Reservation don't have a AddressState
attribute, you can't suppress the change.
The only solution I see here is to compare the $params
values with the $current_lease
values and update $current_lease
only if there is a change in
https://github.com/ansible-collections/community.windows/blob/a45cc22674a1f4e16702622ab3b5d6b41c920396/plugins/modules/win_dhcp_lease.ps1#L312-L342
SUMMARY
If you call the
win_dhcp_lease
module for the same reservation multiple times with the same values, the reservation is always changed.ISSUE TYPE
COMPONENT NAME
win_dhcp_lease
ANSIBLE VERSION
COLLECTION VERSION
CONFIGURATION
OS / ENVIRONMENT
Target OS: Microsoft Windows Server 2019 Standard 10.0.17763.0
STEPS TO REPRODUCE
Step 1: create reservation
Step 2: confirm reservation in AD
Step 3: start client OS
Step 4: confirm reservation in AD
Compared to Step 2, the following fields changed in AD: (HostName), ClientType, AddressState and ServerIP
Step 5: run Ansible again with the same command as in Step 1
Step 6: confirm reservation in AD
Compared to Step 4, the following fields changed in AD: ClientType, AddressState and ServerIP
If the client now renew the DHCP lease, you will see AD changes as in Step 4, and if you then run again the Ansible command as in Step 5, you will see the same changes as in Step 6.
EXPECTED RESULTS
The Ansible command in Step 5 doesn't change the AD DHCP reservation.
ACTUAL RESULTS
The Ansible command in Step 5 change the AD DHCP reservation.