Unable to set DHCP entry ([RestClient::Conflict]: 409 Conflict)

Hello everybody,

I am trying to add a new host using foreman and the proxmox-plugin.

Now I am getting:

  • Create DHCP Settings for frank-soroka.test.zone task failed with the following error: ERF12-6899 [ProxyAPI::ProxyException]: Unable to set DHCP entry ([RestClient::Conflict]: 409 Conflict) for proxy https://foreman.test.zone:8443/dhcp

If I check out the logs, I can see

2021-04-12T19:27:40 3fa2988a [W] Error details for Record 45.133.11.0/45.133.11.147 already exists: <Proxy::DHCP::Collision>: Record 123.123.123.0/123.123.123.147 already exists
/usr/share/foreman-proxy/modules/dhcp_common/server.rb:157:in `add_record'
/usr/share/foreman-proxy/modules/dhcp_common/isc/omapi_provider.rb:29:in `add_record'

Well: It should not be that way :wink:

I configured foreman using:

 foreman-installer --foreman-proxy-dhcp true \
--foreman-proxy-dhcp-managed true \
--foreman-proxy-dhcp-gateway "123.123.123.1" \
--foreman-proxy-dhcp-interface "ens18" \
--foreman-proxy-dhcp-nameservers "123.123.123.1" \
--foreman-proxy-dhcp-range "123.123.123.137 123.123.123.158" \
--foreman-proxy-dhcp-server "123.123.123.136" \
--foreman-proxy-dns true \
--foreman-proxy-dns-managed true \
--foreman-proxy-dns-forwarders "208.67.222.222; 208.67.220.220" \
--foreman-proxy-dns-interface "ens18" \
--foreman-proxy-dns-reverse "123.123.123.in-addr.arpa" \
--foreman-proxy-dns-server "127.0.0.1" \
--foreman-proxy-dns-zone "my.zone" \
--foreman-proxy-tftp true \
--foreman-proxy-tftp-managed true

where the foreman-main server (including it’s proxy) is 123.123.123.136.

I am using foreman 1.24 on Debian 10.

Something new here:

This is the generated dhcpd.conf:

# READ: This file was written the foreman-installer and not by the Foreman
# application. Any updates to subnets in the Foreman database are not
# automatically reflected in this configuration and vice versa. Configuration
# updates like DNS servers or adding/removing subnets must be done both in
# Foreman application and in this configuration preferably via
# foreman-installer. Use custom-hiera.yaml for multiple subnets.
omapi-port 7911;

default-lease-time 43200;
max-lease-time 86400;


not authoritative;


ddns-update-style none;

option domain-name "test.zone";
option domain-name-servers 8.8.8.8;
option ntp-servers none;

allow booting;
allow bootp;

option fqdn.no-client-update    on;  # set the "O" and "S" flag bits
option fqdn.rcode2            255;
option pxegrub code 150 = text ;




# required for UEFI HTTP boot
if substring(option vendor-class-identifier, 0, 10) = "HTTPClient" {
  option vendor-class-identifier "HTTPClient";
}
option architecture code 93 = unsigned integer 16;
if exists user-class and option user-class = "iPXE" {
  filename "http://fm1.test.zone/unattended/iPXE";
} elsif option architecture = 00:06 {
  filename "grub2/shim.efi";
} elsif option architecture = 00:07 {
  filename "grub2/shim.efi";
} elsif option architecture = 00:09 {
  filename "grub2/shim.efi";
} else {
  filename "pxelinux.0";
}

log-facility local7;

include "/etc/dhcp/dhcpd.hosts";
# test.zone
subnet 123.123.123.0 netmask 255.255.255.224 {
  pool
  {
    range 123.123.123.137 123.123.123.158;
  }

  option subnet-mask 255.255.255.224;
  option routers 123.123.123.129;
}

I don’t know which installer-option was setting up this lines:

subnet 123.123.123.0 netmask 255.255.255.224 {
  pool
  {
    range 123.123.123.137 123.123.123.158;
  }

  option subnet-mask 255.255.255.224;
  option routers 123.123.123.129;
}

but if I change them to

subnet 123.123.123.128 netmask 255.255.255.224 {
  pool
  {
    range 123.123.123.137 123.123.123.158;
  }

  option subnet-mask 255.255.255.224;
  option routers 123.123.123.129;
}

the problem seems to be solved.

These are the “dhcp” options. The installer is only capable of creating configuration of single subnet per proxy, however there is a way to define more than one via Hiera YAML configuration files. It is in the docs.

1 Like

Dear Izap please send me a link to the documentation about more than 1 subnets management by Foreman please?

Although I don’t have the link to the documentation, this is a snippet of how I setup additional dhcp pools. I am running Foreman 3.4 with Katello 4.6.

# The foreman-installer options allow only for a single DHCP subnet or DNS domain.
# One way to define more than one subnet is by using a custom configuration file.
# For every additional subnet or domain, create an entry in /etc/foreman-installer/custom-hiera.yaml file:
#

cp /etc/foreman-installer/custom-hiera.yaml /etc/foreman-installer/custom-hiera.yaml.$(date +%s)

# Do not include 192.168.0.0/24 because it was specified with the foreman-installer command as the initial network.

cat << EOF >> /etc/foreman-installer/custom-hiera.yaml

dhcp::pools:
 eth1.lan:
   network: 192.168.1.0
   mask: 255.255.255.0
   gateway: 192.168.1.1
   range: 192.168.1.2 192.168.1.254

 storage.lan:
   network: 192.168.10.0
   mask: 255.255.254.0
   gateway: 192.168.10.1
   range: 192.168.10.2 192.168.11.254

 physical.lan:
   network: 192.168.31.0
   mask: 255.255.255.0
   gateway: 192.168.31.1
   range: 192.168..31.2 192.168.31.254
EOF


# You must add information for each of your subnets to Foreman server because Foreman configures interfaces for new hosts.
# Infrastructure > Subnets
#

hammer subnet create \
  --name 192.168.0.0 \
  --boot-mode Static \
  --description Primary \
  --dhcp-id 1 \
  --dns-primary 192.168.0.12 \
  --dns-secondary 192.168.1.12 \
  --domains local.net \
  --from 192.168.0.2 \
  --gateway 192.168.0.1 \
  --ipam DHCP \
  --locations location1 \
  --mask 255.255.255.0 \
  --mtu 1500 \
  --network 192.168.0.0 \
  --network-type IPv4 \
  --organizations Customer \
  --tftp-id 1 \
  --to 192.168.0.254

hammer subnet create \
  --name 192.168.1.0 \
  --boot-mode Static \
  --description Secondary \
  --dhcp-id 1 \
  --domains local.net \
  --from 192.168.1.2 \
  --ipam DHCP \
  --locations location1 \
  --mask 255.255.255.0 \
  --mtu 1500 \
  --network 192.168.1.0 \
  --organizations Customer \
  --tftp-id 1 \
  --to 192.168.1.254

hammer subnet create \
  --name 192.168.10.0 \
  --boot-mode Static \
  --description Storage \
  --dhcp-id 1 \
  --domains local.net \
  --from 192.168.10.2 \
  --ipam DHCP \
  --locations location1 \
  --mask 255.255.254.0 \
  --mtu 9000 \
  --network 192.168.10.0 \
  --organizations Customer \
  --tftp-id 1 \
  --to 192.168.11.254

hammer subnet create \
  --name 192.168.31.0 \
  --boot-mode Static \
  --description Virtual \
  --dhcp-id 1 \
  --dns-primary 192.168.0.12 \
  --dns-secondary 192.168.1.12 \
  --domains local.net \
  --from 192.168.31.2 \
  --ipam DHCP \
  --locations location1 \
  --mask 255.255.255.0 \
  --mtu 1500 \
  --network 192.168.31.0 \
  --organizations Customer \
  --tftp-id 1 \
  --to 192.168.31.254

In addition, when creating a host with “hammer host create”, there is a bug where you need to restart dhcp for the dhcp file to be updated properly (and another bug where the build flag needs to be set again, and another bug where the tftpboot initrd and vmlinuz get out of whack). For completeness, here are the commands I use to build a host.

(
hammer host delete --name acilrhel7001.local.net
/bin/rm -f /var/lib/tftpboot/boot/rhel-server-7-*
systemctl restart dhcpd

hammer host create \
  --name acilrhel7001 \
  --build false \
  --enabled true \
  --hostgroup rhel-7-server-latest \
  --interface "mac=08:00:27:AA:AA:02, ip=192.168.0.7, type=interface, managed=true, primary=true, provision=true, subnet=192.168.0.0, virtual=false" \
  --interface "mac=08:00:27:AA:AA:03, ip=192.168.1.7, type=interface, managed=true, primary=false, provision=false, subnet=192.168.1.0, virtual=false" \
  --location location1 \
  --managed true \
  --overwrite true \
  --provision-method build

# Must restart dhcpd because /var/lib/dhcpd/dhcpd.leases gets out of wack.
systemctl restart dhcpd

hammer host update \
  --name acilrhel7001.local.net \
  --build true
)
2 Likes

Yeah that’s it. Search for hieara YAML.