Hello everyone,
I’m currently having a problem with the community.windows.win_dhcp_lease module.
I need to reserve IP addresses for our HPE Gen10 servers on a Windows DHCP server. But HPE is a bit on the other side in terms of standards in my opinion. The ILO 5 presents itself with a client ID that looks like this: ILO_MAC, followed by 6 times 0. For example: “00:B1:8A:D1:5A:1F000000”. This is unusual but normal, I think in view of the ILO5 User Guide
Then when I try to reserve an IP address I get the error: Mac address not formatted correctly.
Does anyone have a solution for this? Or should I create my own plugin for this?
Here is my main.yml
- hosts: localhost
name: Create reservation in DHCP
strategy: free
connection: local
gather_facts: False
vars:
mac_addresses_input: "00:B1:8A:D1:5A:1F,00:AA:BB:CC:DD:EE"
mac_addresses: "{{ mac_addresses_input.split(',') }}"
ilo_names_input: "tobi-test,marie-test"
ilo_names: "{{ ilo_names_input.split(',') }}"
gen: "ilo5"
ip_reserved: false
tasks:
- name: Combine MAC and ILO-Names
set_fact:
combined_list: "{{ mac_addresses | zip(ilo_names) | list }}"
- name: Start IP Reservation.
ansible.builtin.include_tasks: ip_reservation_task.yml
loop: "{{ combined_list }}"
loop_control:
loop_var: combined_item
when: not ip_reserved
- name: Display Reserved IPs
debug:
var: reserved_ips
and here is the ip_reservation_task.yml:
---
- name: Set mac address for ILO5
ansible.builtin.set_fact:
current_mac: "{{ combined_item[0] }}000000"
current_ilo_name: "{{ combined_item[1] }}"
when: gen == "ilo5"
- name: Display DHCP result
debug:
msg: "{{ current_mac }} und der name dazu {{ current_ilo_name }}"
- name: Get a free DHCP IP
community.windows.win_dhcp_lease:
type: lease
scope_id: "{{ dhcp_scope_id }}"
mac: "{{ current_mac }}"
state: present
register: dhcp_lease
- name: Check IP reachability via win_ping
ansible.windows.win_ping:
data: "{{ ip_to_check }}"
register: ping_result
- name: Create DHCP lease with "Not Free - Check" comment if IP is reachable
community.windows.win_dhcp_lease:
type: lease
ip: "{{ ip_to_check }}"
scope_id: "{{ dhcp_scope_id }}"
mac: "{{ current_mac }}"
dns_hostname: "{{ current_ilo_name }}"
description: "Not Free - Please Check"
when: ping_result.ping == "pong"
- name: Save IP address with "Not Free - Please Check" comment
set_fact:
allready_reserved: "{{ allready_reserved | default([]) + [ip_to_check] }}"
when: ping_result.ping == "pong"
- name: Create DHCP reservation if IP is free and not reachable
community.windows.win_dhcp_lease:
type: reservation
ip: "{{ ip_to_check }}"
scope_id: "{{ dhcp_scope_id }}"
mac: "{{ current_mac }}"
dns_hostname: "{{ current_ilo_name }}"
description: "Reserved with Ansible"
- name: Save reserved IP address and hostname
set_fact:
reserved_ips: "{{ reserved_ips | default([]) + [ { 'ip': ip_to_check, 'hostname': current_ilo_name } ] }}"
- name: Set ip_reserved flag
set_fact:
ip_reserved: true