Using Parameters in ERB - hostname

**Problem: I am using Satellite 6.7 in an isolated lab environment. I have gotten Discovery and Provisioning working which means I have a lot of the pieces set up at this point. I have 2 different Host groups A and B for now. I’m trying to modify the hostname such that it maps to the group name and a unique count mapping to total ever included in the host group. I’m using ERB in the Discovery Rules to try and set the hostname. I have succeeded as far as <%= @host.hostgroup.name %>-<%= rand(99999) %> . Instead of using the random number I want to start at 1 and increment. I tried creating a hostgroup parameter called count that I intended to increase by 1 every time using a <% @host.hostgroup.count += 1 %> type of element but I can’t figure out how to reference the parameter. Is this the best way to achieve my goal? I’m happy with something simpler

Expected outcome: Hostnames match host group and are incremented A-1, A-2, A-3, etc.

Foreman and Proxy versions: Satellite 6.7

Foreman and Proxy plugin versions: Unknown

Distribution and version: Unknown

Other relevant data:
N/A

Hello, the problem with your incremental solution is that you will likely run into race conditions when multiple hosts are provisioned simultaneously.

Anyway, if you really want this I can help you creating a new macro that would provide a counter but it needs to be bullet-proof so once it dispatches a number it never looks back. This can create “holes” in our numbering scheme (e.g. when provisioning fails) if that’s okay for you.

This will require a code change and probably a new setting holding those numbers.

Here is a macro that will do it for you. Just hotfix your instance and it will work!

https://github.com/theforeman/foreman/pull/8072/files