Share via


Setting environment variable in virtual machine scale set (Linux VM)

Question

Wednesday, June 5, 2019 9:23 AM

Hello all,

I am trying to set environment variables in all scale-set instances. To do this, I added a custom_script_for_linux_extension. The script contained the following information:

#!/bin/bash

export user=test
export password=test123
export secrettoken=67890-9877ghkl

exit

The script deployed successfully but i could not see environment variables. The instances have linux vm (ubuntu).

I even tried the following information but unfortunately the deployment failed saying it cannot access .profile or .bashrc

#!/bin/bash

if [ -z "$user" ]
then
    echo "Setting user information"
    echo "export user=test">>~/.profile
    echo "export password=test123">>~/.profile
    echo "export secrettoken=67890-9877ghkl">>~/.profile
    echo "export user=test">>~/.bashrc
    echo "export password=test123">>~/.bashrc
    echo "export secrettoken=67890-9877ghkl">>~/.bashrc
    . ~/.bashrc
    . ~/.profile

else
      echo "user information is already present"
fi
exit

I am trying to get environment variables in my java problem. How do i set environment variables in azure vmss so that all the current and autoscaled instances have environment variables?

All replies (2)

Wednesday, June 5, 2019 7:45 PM

I would suggest looking into using a Custom image instead of Custom Script Extension to set the variables. 

/en-us/azure/virtual-machine-scale-sets/tutorial-use-custom-image-powershell

This will allow any new instances that get added to your scale set to use that preconfigured image where all the environment variables will already be set. 


Friday, June 14, 2019 10:36 PM

Any update on this? 

If a answer was useful remember to "Up-Vote" and "Mark as Answer" so others in the community can easily find it.