Created
September 1, 2023 12:22
-
-
Save damoun/ee5dc3ca89bd8cb4f8681727c62c02f0 to your computer and use it in GitHub Desktop.
Assign Hetzner Cloud floating IP to a server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Let you assign a floating IP to this server. | |
# Useful for Keepalived | |
# | |
# Require curl & jq | |
API_TOKEN="" | |
FLOATING_IP_ID="" | |
SERVER_ID="" | |
if [ "${SERVER_ID}" == "" ] | |
then | |
SERVER_ID="$(curl --silent -H \"Authorization: Bearer ${API_TOKEN}\" \"https://api.hetzner.cloud/v1/servers?name=$HOSTNAME\"|jq '.servers[0].id')" | |
fi | |
curl \ | |
--silent \ | |
-X POST \ | |
-H "Authorization: Bearer ${API_TOKEN}" \ | |
-H 'Content-Type: application/json' \ | |
-d "{\"server\": ${SERVER_ID}}" \ | |
"https://api.hetzner.cloud/v1/floating_ips/${FLOATING_IP_ID}/actions/assign" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment