Hammer host create fails with Error: usergroup not found

I am trying to create a host using the hammer command and it used to work on Foreman 2.0 and earlier but it doesn’t work on Foreman 2.1.2.

I am not sure if I am missing some new command line option or if the user account has a problem?

hammer  host create \
--owner test1 \
--operatingsystem "rhel 8.2" \
--name "hostname" \
--organization Org \
--location LOC \
--architecture x86_64 \
--medium ots_elr_rhel \
--partition-table partition \
--pxe-loader "PXELinux BIOS" \
--interface="mac=00:50:56:9d:e0:56, ip=192.168.1.1, type=interface, \
domain=domain.com, subnet=192.168.1.0, managed=false, primary=true, provision=true" \
--root-password "Password123"
Could not create the host:
  Error: usergroup not found.

Expected outcome:
I expected the host to be created.

Foreman and Proxy versions:

# rpm -q foreman foreman-proxy
foreman-2.1.2-1.el7.noarch
foreman-proxy-2.1.2-1.el7.noarch

Foreman and Proxy plugin versions:

Distribution and version:

Other relevant data:

[ INFO 2020-09-04T14:29:22 API] GET /api/usergroups

[DEBUG 2020-09-04T14:29:22 Exception] Using exception handler HammerCLIForeman::ExceptionHandler#handle_general_exception
[ERROR 2020-09-04T14:29:22 Exception] Error: usergroup not found.
Could not create the host:
  Error: usergroup not found.
[ERROR 2020-09-04T14:29:22 Exception] 

HammerCLIForeman::ResolverError (usergroup not found.):
    /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli_foreman-2.1.2/lib/hammer_cli_foreman/id_resolver.rb:291:in `pick_result'
    /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli_foreman-2.1.2/lib/hammer_cli_foreman/id_resolver.rb:232:in `find_resource'
    /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli_foreman-2.1.2/lib/hammer_cli_foreman/id_resolver.rb:195:in `get_id'
    /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli_foreman-2.1.2/lib/hammer_cli_foreman/id_resolver.rb:183:in `block (2 levels) in define_id_finders'
    /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli_foreman-2.1.2/lib/hammer_cli_foreman/hosts/common_update_options.rb:141:in `owner_id'
    /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli_foreman-2.1.2/lib/hammer_cli_foreman/hosts/common_update_options.rb:69:in `request_params'
    /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli_katello-0.22.2/lib/hammer_cli_katello/host_content_source_options.rb:10:in `request_params'
    /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli_katello-0.22.2/lib/hammer_cli_katello/host_kickstart_repository_options.rb:10:in `request_params'
    /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-2.1.1/lib/hammer_cli/apipie/command.rb:98:in `extended_request'
    /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-2.1.1/lib/hammer_cli/apipie/command.rb:53:in `send_request'
    /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli_foreman-2.1.2/lib/hammer_cli_foreman/commands.rb:188:in `send_request'
    /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-2.1.1/lib/hammer_cli/apipie/command.rb:34:in `execute'
    /opt/theforeman/tfm/root/usr/share/gems/gems/clamp-1.1.2/lib/clamp/command.rb:63:in `run'
    /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-2.1.1/lib/hammer_cli/abstract.rb:77:in `run'
    /opt/theforeman/tfm/root/usr/share/gems/gems/clamp-1.1.2/lib/clamp/subcommand/execution.rb:11:in `execute'
    /opt/theforeman/tfm/root/usr/share/gems/gems/clamp-1.1.2/lib/clamp/command.rb:63:in `run'
    /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-2.1.1/lib/hammer_cli/abstract.rb:77:in `run'
    /opt/theforeman/tfm/root/usr/share/gems/gems/clamp-1.1.2/lib/clamp/subcommand/execution.rb:11:in `execute'
    /opt/theforeman/tfm/root/usr/share/gems/gems/clamp-1.1.2/lib/clamp/command.rb:63:in `run'
    /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-2.1.1/lib/hammer_cli/abstract.rb:77:in `run'
    /opt/theforeman/tfm/root/usr/share/gems/gems/clamp-1.1.2/lib/clamp/command.rb:132:in `run'
    /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-2.1.1/bin/hammer:147:in `<top (required)>'
    /bin/hammer:23:in `load'
    /bin/hammer:23:in `<main>'

Does anyone have an example of creating a host with the hammer command that works with 2.1.2?
Thanks!

Hi, @jwilliam. Apologizing for the late reply.

I’ve tried the same command and it worked for me. However, I’ve used a user group as an owner. While testing I’ve also noticed that this will fail if the owner is a user.

Recommendation until we fix this:
Try to specify --owner-type User explicitly.

UPD: I’ve created an issue to track this: Bug #30814: Wrong assuming when owner-type is not specified - Hammer CLI - Foreman

2 Likes

@ofedoren adding the --owner-type User fixed the issue for me.
Thank you!

1 Like