ansible-collections / community.windows

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

win_dhcp_lease fix MAC address convert and performance improvements #427

Closed netsandbox closed 1 year ago

netsandbox commented 2 years ago
SUMMARY
ISSUE TYPE
COMPONENT NAME

win_dhcp_lease

jborean93 commented 2 years ago

Hi

Thanks for your contribution, I just wanted to let you know that I am taking some time off and won't be able to review this PR until I get back in a few weeks. Please don't take the silence as I am ignoring your work, just that I won't be around to look at it for a while.

Don't worry about the test failures you see here in the PR, they are known problems with dependency resolution that still need be to fixed on our side.

If you have any questions please direct them to #ansible-windows on Libera chat, details on this can be found at https://docs.ansible.com/ansible/latest/community/communication.html#ansible-community-on-irc.

Thanks

ifelsefi commented 2 years ago

Does this explain why I get random failures such as below:

Failed to get lease information for ClientId d08e79f128b8 from DHCP server dhcp.domain.example.com.
At line:398 char:30
+ ...  $new_lease = Get-DhcpServerv4Lease -ClientId $mac -ScopeId $scope_id
+                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidType: (d08e79f128b8:root/Microsoft/...cpServerv4Lease) [Get-DhcpServerv4Lease], CimException
    + FullyQualifiedErrorId : DHCP 20016,Get-DhcpServerv4Lease

ScriptStackTrace:
failed: [dhcp.domain.example.com] (item=node.domain.example.com) => {
    "ansible_loop_var": "item",
    "changed": false,
    "invocation": {
        "module_args": {
            "description": "servers in rack argblah",
            "dns_hostname": "node.domain.example.com"",
            "dns_regtype": "aptr",
            "duration": null,
            "ip": "10.69.50.21",
            "mac": "d0-8e-79-f1-28-b8",
            "reservation_name": "node.domain.example.com",
            "scope_id": "10.69.49.0",
            "state": "present",
            "type": "reservation"
        }
    },
    "item": "node.domain.example.com",
    "msg": "Could not create DHCP lease: Failed to get lease information for ClientId d08e79f128b8 from DHCP server dhcp.domain.example.com."
}

My play YAML:

- name: create dhcp reservations
  tags: nodes
  community.windows.win_dhcp_lease:
    type: reservation
    ip: "{{ hostvars[item].idrac_ip }}"
    scope_id: "{{ oob_scope }}"
    mac: "{{ hostvars[item].idrac_mac }}"
    dns_regtype: aptr
    dns_hostname: "{{ hostvars[item].idrac_hostname }}"
    reservation_name: "{{ hostvars[item].idrac_hostname }}"
    description: 'servers in rack argblah'
  loop: "{{ groups['nodes'] }

My vars YAML:

[nodes]
node idrac_mac='d0-8e-79-f0-5a-a0' idrac_hostname='node.domain.example.com' idrac_ip='10.69.50.11'

I always get a lease created but randomly the reservations fail. The scope is correct.

If I run the playbook a second time it's successful as both lease and reservation are created.

Thank you!

netsandbox commented 1 year ago

@jborean93 changelog added.