Home > Enterprise >  cloudinit output shows eipalloc-09e7274dd3c641ae6: value too great for base (error token is "09
cloudinit output shows eipalloc-09e7274dd3c641ae6: value too great for base (error token is "09

Time:11-29

I'm trying to associate the Elastic IP address with Auto scaling group, so whenever the autoscaling triggers it will automatically associate with the EIP.

For this I'm trying to add the script in user data.

My intention is to we have 2 servers so its associated with 2 EIP's, whenever the autoscaling triggers it has to check whether the EIP is free or not if its free it has to associate with that instance using the instance id.

Below is my script where I'm getting the error

I'm getting this error in cloudinit logs eipalloc-09e7274dd3c641ae6: value too great for base (error token is "09e7274dd3c641ae6") for the line EIP_LIST=$[eipalloc-05b7bbe1affef1765,eipalloc-0dd1d12d42e2890ab]


`echo "Testing EIP automation" 

INSTANCE_ID=$(ec2-metadata --instance-id | cut -d " " -f 2);
  MAXWAIT=10
  # Get list of EIPs
  EIP_LIST=$[eipalloc-05b7bbe1affef1765,eipalloc-0dd1d12d42e2890ab]
  # Iterate over EIP list
  for EIP in $${EIP_LIST}; do
  echo "Checking if EIP with ALLOC_ID[$EIP] is free...."
    ISFREE=$(aws ec2 describe-addresses --allocation-ids $EIP --query Addresses[].InstanceId --output text --region ap-south-1)
     STARTWAIT=$(date  %s)
      while [ ! -z "$ISFREE" ]; do
        if [ "$(($(date  %s) - $STARTWAIT))" -gt $MAXWAIT ]; then
        echo "WARNING: We waited 30 seconds, we're forcing it now."
        ISFREE=""
        else
        echo "Waiting for EIP with ALLOC_ID[$EIP] to become free...."
        sleep 3
        ISFREE=$(aws ec2 describe-addresses --allocation-ids $EIP --query Addresses[].InstanceId --output text --region ap-south-1)
        fi
        done
        echo Running: aws ec2 associate-address --instance-id $INSTANCE_ID --allocation-id $EIP --allow-reassociation --region ap-south-1
        aws ec2 associate-address --instance-id $INSTANCE_ID --allocation-id $EIP --allow-reassociation --region ap-south-1`


CodePudding user response:

The proper way to define a list in bash is:

EIP_LIST=(eipalloc-05b7bbe1affef1765 eipalloc-0dd1d12d42e2890ab)

not

EIP_LIST=$[eipalloc-05b7bbe1affef1765,eipalloc-0dd1d12d42e2890ab]
  • Related