Skip to content

Instantly share code, notes, and snippets.

@superseb
Created February 12, 2018 15:00
Show Gist options
  • Save superseb/8bc5e51a1019b9139b365fd9bc035583 to your computer and use it in GitHub Desktop.
Save superseb/8bc5e51a1019b9139b365fd9bc035583 to your computer and use it in GitHub Desktop.
Delete disconnected hosts in Rancher environment
#!/bin/bash
RANCHER_URL=http://rancher_server:8080
ENV=1a7
for host in `curl -s http://$RANCHER_URL/v2-beta/projects/$ENV/hosts/ | jq -r '.data[] | select(.state == "disconnected") | .id'`; do echo Deactivating $host; curl -X POST -d '{}' http://$RANCHER_URL/v2-beta/projects/$ENV/hosts/$host/?action=deactivate; echo Deleting $host; curl -X DELETE -H 'Accept: application/json' http://$RANCHER_URL/v2-beta/projects/$ENV/hosts/$host; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment