Unable to Change Host Location via Hammer

Problem:
I’m not able to update the location with hammer command which we need to migrate hosts to new Katello system.

hammer host update --name test.example.com --location “site a” --organization orgname
Could not update the host:
Resource host not found by id ‘69’

Expected outcome:
To change the location of hosts using hammer host update

Foreman and Proxy versions:
1.22.0-1

Foreman and Proxy plugin versions:
foreman-tasks - 0.15.7
foreman_chefs - 0.8.1
foreman_discoverys - 15.0.0
foreman_dockers - 5.0.0
foreman_remote_executions - 1.8.2
katellos - 3.12.1

Other relevant data:
The following article said it was “Fixed In Version: tfm-rubygem-hammer_cli_foreman-0.17.0.6-1”
I upgraded to tfm-rubygem-hammer_cli_foreman-0.17.2-1.el7.noarch, but still get the same error.

https://bugzilla.redhat.com/show_bug.cgi?id=1679300

Also, there is reference to hammer_cli_foreman-0.18 at Bug #26536: Unable to Change Host Location via Hammer - Hammer CLI - Foreman which is not available for my version.

logs
2019-08-22T15:34:41 [I|app|da69d322] Couldn't find Host::Managed with 'id'=69 [WHERE "hosts"."type" IN ('Host::Managed') AND "hosts"."organization_id" = $1 AND "hosts"."location_id" = $2 AND "taxonomies"."type" IN ('Location') AND ("taxonomies"."id" = 3 OR "taxonomies"."title" = '3')] (ActiveRecord::RecordNotFound)

The host is migrated from another katello system. And “hammer host info --id 69” does display information, and “hammer host list” also displays this host.

As that bug report is for Satellite the version refers to the hammer package in Satellite repos. Patched version of hammer CLI 0.17.x was not released yet in the Foreman repos.

If you can’t wait you can try to update to hammer 0.18 rpms from the 1.23 repos just be aware it is not tested and you may need to update also some hammer plugin rpms such as hammer-cli-katello. Another option would be to temporarily install hammer 0.18 from gems or from github checkout (note it needs to be neither same machine nor root user so you can have isolated vm for that). There are some hints in https://github.com/theforeman/hammer-cli/blob/master/doc/installation.md#installation.

Regards,
Martin

Thanks for the suggestions. I used the option of installing the gem on another system.

$ hammer --version
hammer (0.18.0)

  • hammer_cli_foreman (0.18.0)
  • hammer_cli_katello (0.19.0)

However, I’m still receiving the error:

Could not update the host:
Resource host not found by id ‘69’

Couldn’t find Host::Managed with ‘id’=69 [WHERE “hosts”.“type” IN (‘Host::Managed’) AND “hosts”.“organization_id” = $1 AND “hosts”.“location_id” = $2 AND “taxonomies”.“type” IN (‘Location’) AND (“taxonomies”.“id” = 3 OR “taxonomies”.“title” = ‘3’)] (ActiveRecord::RecordNotFound)

Is it possible that there is another issue involved with changing subscriptions to a different katello systems?

Here the --location and --organization set the scope in which the update is performed. In hammer >= 0.18.0 there should be new option --new-organization and --new-location that should serve to update those fields. What you probably need is:
hammer host update --name test.example.com --new-location “site a” --new-organization orgname

Let me know if that dind’t help.

2 Likes

Perfect. That was the solution. Thanks so much for your help.

1 Like

@mbacovsky, do you maybe know if you can use wildcards with hammer cli? for example --name *.example.com

No, we do not.