0

I have created a few environment variables in my Linux VM hosted in Azure. The environment variables reside in ~/.profile file.

The variables are:

admin_user=heroadmin
export admin_user
admin_password=heropassword
export admin_password
admin_secret=0987heroSecret

The variables will be retrieved in a java class. Using the environment variable, I will call RESST endpoints using the above environment variables retrieved via [System.getenv("admin_user")]

I read somewhere that when I deprovision and create image all the changes and files will be lost.

If I deprovision the virtual machine and create scale set with multiple instances from the virtual machine image, Will I be able to get environment variables in my scale set instances?

I do not want to set environment variables manually in each instance as auto-scaling is enabled in scale set, so new VM instances get created frequently.

lambad
  • 1,046
  • 10
  • 21

1 Answers1

1

no, you'd need to use some sort of startup script (like Azure VM Script extension) to populate those keys\values for the VMSS. VMSS images come up from the golden image you specified when you created VMSS and they do not contain changes you manually applied to them.

4c74356b41
  • 69,186
  • 6
  • 100
  • 141
  • thanks for the response but the script I added did not work. I tried to add a custom script extension. The script is a shell script which looks like !/bin/bash export admin_user=heroadmin export admin_password=heropassword export admin_secret=0987heroSecret The above approach didn't work, any help plz? – lambad Jun 05 '19 at 00:08
  • Did not understand what you commented. Can you plz elaborate on how I can make it work? – lambad Jun 05 '19 at 05:59
  • https://stackoverflow.com/questions/13046624/how-to-permanently-export-a-variable-in-linux probably need to export it permanently, not just to the session – 4c74356b41 Jun 05 '19 at 06:00
  • I tried to export it permanently but cannot access .profile or bashrc. The error i got is cannot create ~/.profile: Directory nonexistent – lambad Jun 05 '19 at 09:34
  • you have to figure out under which user the script extension works and push these changes to the user application works under, I suppose – 4c74356b41 Jun 05 '19 at 09:55