This commit is contained in:
@@ -92,6 +92,58 @@ CONFIG_FILE="/etc/teleport.yaml"
|
||||
# Edit the teleport.yaml file to update the nodename
|
||||
sed -i "s/^ nodename:.*/ nodename: $HOSTNAME/" "$CONFIG_FILE"
|
||||
|
||||
# Function to add labels to teleport.yaml
|
||||
add_teleport_labels() {
|
||||
if [ -n "$TELEPORT_LABELS" ]; then
|
||||
echo "Adding Teleport labels from TELEPORT_LABELS environment variable..."
|
||||
|
||||
# Check if ssh_service section exists
|
||||
if ! grep -q "ssh_service:" "$CONFIG_FILE"; then
|
||||
echo "Error: ssh_service section not found in teleport.yaml"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Check if labels section already exists under ssh_service
|
||||
if grep -q " labels:" "$CONFIG_FILE"; then
|
||||
echo "Labels section already exists, updating..."
|
||||
# Remove existing labels section
|
||||
sed -i '/^ labels:/,/^[^ ]/ { /^ labels:/d; /^[^ ]/!d; }' "$CONFIG_FILE"
|
||||
fi
|
||||
|
||||
# Add labels section after ssh_service
|
||||
sed -i '/^ssh_service:/a\ labels:' "$CONFIG_FILE"
|
||||
|
||||
# Parse TELEPORT_LABELS and add each label
|
||||
IFS=',' read -ra LABELS <<< "$TELEPORT_LABELS"
|
||||
for label in "${LABELS[@]}"; do
|
||||
# Trim whitespace
|
||||
label=$(echo "$label" | xargs)
|
||||
|
||||
# Check if label contains colon
|
||||
if [[ "$label" == *":"* ]]; then
|
||||
key=$(echo "$label" | cut -d':' -f1 | xargs)
|
||||
value=$(echo "$label" | cut -d':' -f2- | xargs)
|
||||
|
||||
if [ -n "$key" ] && [ -n "$value" ]; then
|
||||
echo " $key: $value" >> "$CONFIG_FILE"
|
||||
echo "Added label: $key = $value"
|
||||
else
|
||||
echo "Warning: Invalid label format '$label'. Expected format: key:value"
|
||||
fi
|
||||
else
|
||||
echo "Warning: Label '$label' does not contain colon separator. Expected format: key:value"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "Teleport labels added successfully"
|
||||
else
|
||||
echo "No TELEPORT_LABELS environment variable set, skipping label configuration"
|
||||
fi
|
||||
}
|
||||
|
||||
# Add labels to teleport configuration
|
||||
add_teleport_labels
|
||||
|
||||
# Start the cron service
|
||||
service cron start
|
||||
nohup teleport start &
|
||||
|
||||
Reference in New Issue
Block a user