Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

win_dhcp_lease fix MAC address convert and performance improvements #427

Merged

Conversation

netsandbox
Copy link
Contributor

SUMMARY
ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

win_dhcp_lease

This always use the mac address format with dashes.

Fixes ansible-collections#291
If MAC and IP are defined, only try to find existing lease by MAC.
This saves us a second Get-DhcpServerv4Lease call and improve the
performance of this module.
@jborean93
Copy link
Collaborator

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
Copy link

ifelsefi commented Aug 30, 2022

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!

Copy link
Collaborator

@jborean93 jborean93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good, are you able to add a changelog fragment as per https://docs.ansible.com/ansible/latest/community/development_process.html#creating-a-changelog-fragment to document this bugfix please.

@netsandbox
Copy link
Contributor Author

@jborean93 changelog added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

win_dhcp_lease Module not Mac Address Conversion not working correclty
3 participants