Trigger DNS registration

We want to trigger already installed VMs to register to our DNS via smart proxy

Expected outcome:
Have DNS of already installed VMs.

Foreman and Proxy versions:
Foreman and Proxy plugin versions:

Other relevant data:
We use a Windows AD DNS Server and the smart proxy on that. When installing a new VM via foreman DNS registration works very well.
But we have a bunch of VM which are installed before we had foreman and they have no DNS.

So is there a way to trigger that registration manual for already installed nodes? Of course, they are known in foreman.


1 Like

@tbrisker Can you give a hint? :slight_smile:

What definitely will work is rebuilding the systems. But why rebuild 1-x hosts when just the DNS registration is missing (was not done in past).

You could perhaps try to create a script which takes the data from foreman and works directly with the smart proxy api to trigger a registration outside of the regular orchestration code which handles it for new hosts. I’m not too familiar with the exact commands you would need to issue to the smart proxy, perhaps you can try to monitor the requests foreman sends to the proxy during provisioning and duplicate those. or maybe @lzap has a better idea?

Yeah unfortunately there is no way of doing that other than talking to smart proxy API. It’s is very simple, search for dns_api.rb and you will get it. REST based with few parameters.

Thanks again, Sir!

Do we have some examples or docs for this purpose?

Nope. And - nope. Wait!

This is an example in Ruby against the DNS API to test Infoblox. You need the very same thing.

I’ve just tested to rebuild an existing hosts. After being installed and Puppet agent run, I didn’t find a DNS registration in our DNS server, even the Foreman DNS proxy is running.
So it seems, that it only works when discovery finds a node and installs it from the scratch.
Is this behavior correct?

It looks like a host rebuild triggers the rebuild_dns method:

That means you can loop over all the hosts and their interfaces and call rebuild_dns. This will be slow and there’s probably a lot of edge cases. 100% untested:

Host::Managed.all.each do |host|
  puts "Rebuilding DNS for #{host}"
  host.interfaces.each do |interface|
    if interface.dns_ready?
      if interface.rebuild_dns
        puts "  Rebuild interface #{interface}"
        puts "  Failed to rebuild interface #{interface}"

From my understanding this should forcefully recreate the DNS records for every interface on every host when it’s supposed to manage the DNS there.

Again, I have not tested this so I’d recommend you try this in a test setup

How can I call this command?

It’s not a command but an (internal) API. You’ll have to do it on the console but it’s probably easier to wrap it in a Rake task. is a good example. Then drop it in the right place. That particular task is exposed as foreman-rake permissions:reset (note the namespace and task name).

It does not. I’ve just tested it again. Pressed the build button, host restart and boot over network, OS is being installed and after that Puppet is being installed. No DNS entry. :frowning:

You shouldn’t even need to restart the host. Entering build mode and leaving it should be sufficient I think. Are the network interfaces marked as Managed? Do they have a domain assigned? Does the domain have a DNS proxy assigned?

I´ve enabled the infoblox smart proxy (dns & dhcp), we need next free ip for new host, but once I setup the subnet as DCHP, the “sugggest ip” is not giving any IP. I can´t see any error, is there a way to run this gems by “command line” in debug/verbose mode to know what´s behind?

The free IP call should reach out to your DHCP smart proxy and recent version should do a query into Infoblox to find out if next available IP has a host reservation or not. Then it repeats until it finds one.

Keep in mind that Infoblox IPAM is completely ignored at this point, IPAM integration is not yet implemented.

1 Like

Would be cool to have this DNS registration action in the task menu.