No location / Organization if host added by default from puppet run

Problem:

No location / Organization if host added by default from puppet run

When registering a node for the first time, the default location and organization are set to blank and the GUI wont allow them to be changed.

example
I have set Location/Organization to the same thing as Environment. for testing purposes “dev”

host update --name host-dev.demo.domain --new-organization-id 1 --new-location-id 2 --hostgroup-title dev/hostgroup1

if I try the above workaround using title it fails, this shouldnt

host update --name host-dev.demo.domain --new-organization-title dev --new-location-title dev --hostgroup-title dev/hostgroup1

Expected outcome:
To be able to set the name via title

Foreman and Proxy versions:
2.1.0
Foreman and Proxy plugin versions:
2.1.0
Distribution and version:
puppet 6.17 / CentOS Linux release 7.8.2003 (Core)

Other relevant data:

Is it possible to have the puppet registration run default to an organization/location instead of being blank. for example what ever the default has been set to, which in my case would have been “dev”

I have read cases like this before, however could not see a solution other than the above hammer based workaround, which is not really ideal as it requires access to the foreman server.

How do I get default organization / location to be enabled and working, so the hammer workaround and access to the foreman cli is not needed.

Setting this in the WebInterface is also something I would rather not need to do. Defaulting to something that is not blank is what should happen

please provide url if this is duplicate. As I am using the latest version of foreman with puppet6

There are settings for default location and default organization that should apply in these cases and set the default. If they don’t than that’s a bug :slight_smile:
Additionally, there are settings for Organization fact and Location fact that allow you to define a custom fact name which will set the organization and location if present in the host facts.

I have the default location and default organization set to dev via hammer on the install of foreman2

So the puppet run is ignoring this and they are getting blank.

please explain how I can use
“Additionally, there are settings for Organization fact and Location fact that allow you to define a custom fact name which will set the organization and location if present in the host facts.”

All of these settings are accessible from the Settings -> Puppet in the UI or from hammer settings list iirc in hammer.
Please confirm that the values for the defaults are correctly set to the location/organization title - it has to be a full match or it won’t be properly chosen.
For the custom fact, you need to provide a custom fact to puppet with the name defined in the setting and the value of the location/organization title you want to assign the host to.

For the custom fact, may sound daft, but what is the exact name of the fact needed?

I run this
ENV=dev
sudo -E hammer -u admin -p ${HAM_AP} settings set --name default_location --value “${ENV}”
sudo -E hammer -u admin -p ${HAM_AP} settings list |grep default_location |awk -F’|’ ‘{print$1" "$2}’
sudo -E hammer -u admin -p ${HAM_AP} settings set --name default_organization --value “${ENV}”
sudo -E hammer -u admin -p ${HAM_AP} settings list |grep default_organization |awk -F’|’ ‘{print$1" "$2}’

As my dev vm has been messed around with a lot, it is currently being reset, so I can get a full clean test done.

Also when installing I set this
starting foreman-installer --foreman-initial-location “dev” --foreman-initial-organization “dev” rest of line

Just did a new build to confirm we are looking at bug here. The webconsole is showing the value as blank, yet hammer is saying it is set.

here is the diagnostics on this.

foreman_bug1

CLI
hammer> settings set --name default_organization --value dev
Setting [default_organization] updated to [dev].
hammer> settings set --name default_location --value dev
Setting [default_location] updated to [dev].

[root@NODENAME vagrant]# systemctl restart foreman-proxy
[root@NODENAME vagrant]# systemctl restart foreman
[root@NODENAME vagrant]# systemctl restart puppetserver

[root@NODENAME vagrant]# hammer -u admin -p PASSWORD settings list
default_location | Default location | dev | Hosts created after a puppet run that did not send a location fact will be pl…
default_organization | Default organization | dev | Hosts created after a puppet run that did not send a organization fact will b…
default_puppet_environment | Default Puppet environment | dev | Foreman will default to this puppet environment if it cannot auto detect one

HAMMER showing correct values, however in the webconsole the values are blank

setting facts on the CLI from the client side
method I assume
Facter_location dev ; Facter_organization dev ; puppet agent -t

Cant help noticing the Case issues above!
[default_organization] yet gui calls it [default_organisation]
Organi{z|s}ation or organi{z|s}ation
Location or location

Is this the issue, things are not getting set due the leading upper case element name.

The value displayed in the UI for the setting name is a human-readable string that gets translated, so in your case I’m assuming you have the en_GB locale set where “organization” is translated to “organisation”. In any case the setting name in the db is default_organization, which you can see if you hover on the name in the ui.
Do you have both a location and an organization both named dev? note that this value is case sensitive and refers to the title and not name of the organization/location (e.g. if you have UK/Dev location, you need to set the setting to UK/Dev and not dev). Can you share the output of hammer locations list just to make sure?

no, for setting custom fact on the clients please follow the guidelines in the link I shared before:

https://puppet.com/docs/puppet/6.17/custom_facts.html

hammer> location list
—|------------|------------|------------

ID TITLE NAME DESCRIPTION
2 “dev” “dev”
------------ ------------ ------------

hammer> organization list
—|------------|------------|------------

ID TITLE NAME DESCRIPTION
1 “dev” “dev”
------------ ------------ ------------

The above lab version names(dev) to provide support with some detail around the isue of the empty.

Clearly this is not what is going to be used in production and is just provide input to support

In the webconsole, the drop down box does offer “dev” as an option, so it is possible to set it( although I would rather have hammer and gui matching" ) not sure why it is adding diouble quotes to the name

Once it is set in the webconsole, a default puppet registration goes into the correct location/organization.

So fix why hammer is not updating it and its fixed.

Looks like the name you gave to the location and organization includes the quotes as part of the name - it started from the installer where you added the quotes to the name.
You can rename them to not include the quotes or add the quotes to your hammer command as well.

I will rebuild removing the quotes! see if having them match will work or not.

Post install the entry is empty in webconsole. I have to select the option from a drop down box

Well many thanks! seems having double quotes on the installer line was causing it an issue and post install the value is populated in webconsole without quotes

It still.stands that changing the value via hammer, didnt update the setting in the webconsole.