You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/virtual-machines/linux/cloudinit-update-vm.md
+64-20Lines changed: 64 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ author: cynthn
5
5
ms.service: virtual-machines
6
6
ms.collection: linux
7
7
ms.topic: how-to
8
-
ms.date: 02/18/2022
8
+
ms.date: 03/29/2023
9
9
ms.author: cynthn
10
10
ms.subservice: cloud-init
11
11
---
@@ -16,15 +16,10 @@ ms.subservice: cloud-init
16
16
This article shows you how to use [cloud-init](https://cloudinit.readthedocs.io) to update packages on a Linux virtual machine (VM) or virtual machine scale sets at provisioning time in Azure. These cloud-init scripts run on first boot once the resources have been provisioned by Azure. For more information about how cloud-init works natively in Azure and the supported Linux distros, see [cloud-init overview](using-cloud-init.md)
17
17
18
18
## Update a VM with cloud-init
19
-
For security purposes, you may want to configure a VM to apply the latest updates on first boot. As cloud-init works across different Linux distros, there is no need to specify `apt` or `yum` for the package manager. Instead, you define `package_upgrade` and let the cloud-init process determine the appropriate mechanism for the distro in use.
20
19
21
-
For this example, we will be using the Azure Cloud Shell. To see the upgrade process in action, create a file named *cloud_init_upgrade.txt*and paste the following configuration.
20
+
For security purposes, you may want to configure a VM to apply the latest updates on first boot. As cloud-init works across different Linux distros, there is no need to specify `apt`, `zypper` or `yum` for the package manager. Instead, you define `package_upgrade`and let the cloud-init process determine the appropriate mechanism for the distro in use.
22
21
23
-
Select the **Try it** button on the code block below to open the Cloud Shell. To create the file and see a list of available editors in the Cloud Shell, type the following:
24
-
25
-
```azurecli-interactive
26
-
sensible-editor cloud_init_upgrade.txt
27
-
```
22
+
For this example, we will be using the Azure Cloud Shell. To see the upgrade process in action, create a file named *cloud_init_upgrade.txt* and paste the following configuration. You can use any editor you wish. Make sure that the whole cloud-init file is copied correctly, especially the first line.
28
23
29
24
Copy the text below and paste it into the `cloud_init_upgrade.txt` file. Make sure that the whole cloud-init file is copied correctly, especially the first line.
30
25
@@ -37,47 +32,96 @@ packages:
37
32
38
33
Before deploying, you need to create a resource group with the [az group create](/cli/azure/group) command. An Azure resource group is a logical container into which Azure resources are deployed and managed. The following example creates a resource group named *myResourceGroup* in the *eastus* location.
39
34
40
-
```azurecli-interactive
41
-
az group create --name myCentOSGroup --location eastus
35
+
```azurecli-interactive
36
+
az group create --name myResourceGroup --location eastus
42
37
```
43
38
44
39
Now, create a VM with [az vm create](/cli/azure/vm) and specify the cloud-init file with the `--custom-data` parameter as follows:
45
40
46
-
```azurecli-interactive
41
+
```azurecli-interactive
47
42
az vm create \
48
-
--resource-group myCentOSGroup \
49
-
--name centos83 \
50
-
--image OpenLogic:CentOS:8_3:latest \
43
+
--resource-group myResourceGroup \
44
+
--name vmName \
45
+
--image imageCIURN \
51
46
--custom-data cloud_init_upgrade.txt \
52
47
--admin-username azureuser \
53
48
--generate-ssh-keys
54
49
```
55
50
56
-
SSH to the public IP address of your VM shown in the output from the preceding command. Enter your own **publicIpAddress** as follows:
51
+
> [!NOTE]
52
+
> Replace **myResourceGroup**, **vmName**, and **imageCIURN** values accordingly. Make sure an image with Cloud-init is chosen.
53
+
54
+
SSH to the public IP address of your VM shown in the output from the preceding command. Enter your own **user** and **publicIpAddress** as follows:
57
55
58
56
```bash
59
-
ssh azureuser@<publicIpAddress>
57
+
ssh <user>@<publicIpAddress>
60
58
```
61
59
62
-
Run the package management tool and check for updates.
60
+
Run the package management tool and check for updates:
61
+
62
+
# [RHEL/CentOS/Oracle Linux](#tab/rhel)
63
+
64
+
- Execute the following command to confirm there are no pending updates
63
65
64
66
```bash
65
-
sudo yum update
67
+
sudo yum check-update
66
68
```
67
69
68
-
As cloud-init checked for and installed updates on boot, there should be no additional updates to apply. You see the update process, number of altered packages as well as the installation of `httpd` by running `yum history` and review the output similar to the one below.
70
+
As cloud-init checked for and installed updates on boot, there should be no additional updates to apply.
71
+
72
+
- You can see the update process, number of altered packages as well as the installation of `httpd` by running the following command and review the output.
69
73
70
74
```bash
75
+
sudo yum history
76
+
```
77
+
78
+
```output
71
79
ID | Command line | Date and time | Action(s) | Altered
0 commit comments