Weird hammer cli behaviour

Problem:
Tried to create a server via https://github.com/xnaveira/foreman-host-builder but it failed with the following message:

File "./host-builder.py", line 124, in <module>
build_host['location_id'] = locid[0]['Id']
KeyError: 'Id'

The script was working for the last months without problems. At first we used it with Foreman 1.17.

Expected outcome:
New server in foreman

Foreman and Proxy versions:
Foreman 1.19.0

Foreman and Proxy plugin versions:
Katello 3.8
Used API version 2

Other relevant data:
This is an interesting problem…we fetch locations with

hammer location list

Using Windows 10 with Xterm we get the following:

{
  "ID": 27,
  "Title": "XXX",
  "Name": "XXX",
  "Beschreibung": ""
},

Should have been easy…wrong fieldname used. But if we use SSH from an RHEL6 Server to connect to the foreman server, hammer cli output was this:

{
  "Id": 27,
  "Title": "XXX",
  "Name": "XXX",
  "Beschreibung": ""
},

So it seems that hammer creates different outputs depending on the OS the user is connecting from. Both tests used the same user.

Any ideas?

Regards,
Martin

Hi Martin,
could you please share hammer --version of both hammers? If one is >= 0.15 and one is < 0.15 there may be a fix for Bug #17010: Hammer JSON output uses inconsistent capitalization - Hammer CLI - Foreman in the way. Could you please confirm?

Regards,
Martin

As we’re using the same machine, there is only one hammer.

To explain it in a different way… we have one Foreman server e.g. foreman.xyz.de

To get the first mentioned dataset with uppercase “id” we connect via SSH from our Windows machine to a RHEL6 server to use it as a jump host. From there we connect again via SSH to the Foreman server.

At this point we trigger “hammer location list” and get the dataset as shown.

If we connect directly from our Windows client to the Foreman server via SSH (XTerm or Putty, makes no difference), the “hammer location list” output is different as shown in the second example.

One idea or possible explanation from my colleague is the LANG setting.

Regards,
Martin

Thanks for the explanation!
I’m not aware of any way how the behavior you describing could happen. Currently I don’t have a box with Windows to try to reproduce. Before I get one could you please compare (with diff perhaps) output of hammer -d location list from both scenarios if it reveal any differences?
What version of hammer do you use? Is it 0.14.0 from Foreman 1.19 repos?
Is the env set the same in both scenarios?

It would be best to find the root cause but as a possible workaround you could try to update hammer to 0.15.1 and enforce the capitalization of the JSON output in ~/.hammer/cli_config.yml (if your environment allows it).

I posted the differences already in my first post.

Hammer version on the production server is 0.12.0 from Foreman 1.17.1 repos.
On the dev server it is indeed 0.14.0.

As far as I can see the env is not set on Windows but on Linux. My Windows is set to German, the Linux machine has en_US. Maybe that’s the issue my colleague mentioned.

Updating takes time but we definately are going to test it with 1.20.