Hammer bulk empty hosts delete

Expected outcome:
Team,

Please help me to delete bulk empty hosts using hammer search query, like if IP field is empty.

----|------------------------------------------|--------------------|------------|----------------|-------------------|--------------
ID  | NAME                                     | OPERATING SYSTEM   | HOST GROUP | IP             | MAC               | GLOBAL STATUS
----|------------------------------------------|--------------------|------------|----------------|-------------------|--------------
112 | ad-client-1                              |                    |            |                |                   | Error
82  | ad-client-2                              |                    |            |                |                   | Error
118 | adcontrol                                |                    |            |                |                   | Error
94  | ap-api-server                            |                    |            |                |                   | Error
97  | ap-api-server-2                          |                    |            |                |                   | Error
116 | ap-app                                   |                    |            |                |                   | Error

Other relevant data:

Hi @Rajeshunix13,

Sorry for the late reply, but unfortunately there is no way how to delete a few hosts in one hammer command. At least for now.

If you have Katello plugin installed then you can try API endpoints for bulk actions on hosts provided by that plugin.

1 Like

Below helped me to delete hosts which are dont have ip.

hammer --csv host list|awk -F, ‘!length($5)’|cut -d’,’ -f1 > /tmp/a

for i in $(cat /tmp/a); do hammer host delete --id $i ; done

1 Like

You could use API for the delete calls straight away - much faster. Also doing it asynchronously speeds it up further.

Anyway, when it works…

1 Like