-1

I want to deploy a redHat enterprise linux machine in azure public cloud whose packeges are all up to date.

Is there any way to run the command "yum update -y" (and maybe other 'yum install' commands as well) automatically as part of the deployment process or right after the machine's first boot?

Thanks

sayan saha
  • 91
  • 2
  • 8
MrSonic
  • 363
  • 3
  • 10

2 Answers2

0

You can provide a cloud-init config file(in YAML format) under the custom data section when creating the VM on Azure.

#cloud-config
package_upgrade: true
packages:
  - nginx
  - nodejs
  - npm
runcmd:
  - yum update -y #same as package_upgrade: true
  - npm i express -y

documentation link

enter image description here

sayan saha
  • 91
  • 2
  • 8
  • Hello, thank you for your answer. Unfortunately, It seem that It does not work for me.. As you suggested, Into the Custom data window, I past a short YAML config-file: #config-file package_upgrade: true runcmd: - mkdir /mydir #for sainty check None of the packages were updated and the directory "mydir" wasn't created. Do you have any idia why? Thanks – MrSonic Nov 04 '20 at 21:19
0

For your purpose, I will suggest the VM extension or the CLI command az vm run-command invoke:

az vm run-command invoke -g MyResourceGroup -n MyVm --command-id RunShellScript --scripts "yum update -y"

or PowerShell command Invoke-AzVMRunCommand:

Invoke-AzVMRunCommand -ResourceGroupName 'rgname' -VMName 'vmname' -CommandId 'RunPowerShellScript' -ScriptPath 'sample.ps1' -Parameter @{param1 = "var1"; param2 = "var2"}

To update the packages in the VM, it should be after the creation of the VM, because the VM always provision the VM in that time, not update. So I don't think the cloud-init is a possible way.

Charles Xu
  • 29,862
  • 2
  • 22
  • 39