Skip to content

Commit 3c8af84

Browse files
authored
Merge pull request #232665 from divargas-msft/patch-6
[Doc-a-thon] Updating cloudinit-update-vm
2 parents 2da2186 + 2044225 commit 3c8af84

File tree

1 file changed

+64
-20
lines changed

1 file changed

+64
-20
lines changed

articles/virtual-machines/linux/cloudinit-update-vm.md

Lines changed: 64 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ author: cynthn
55
ms.service: virtual-machines
66
ms.collection: linux
77
ms.topic: how-to
8-
ms.date: 02/18/2022
8+
ms.date: 03/29/2023
99
ms.author: cynthn
1010
ms.subservice: cloud-init
1111
---
@@ -16,15 +16,10 @@ ms.subservice: cloud-init
1616
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)
1717

1818
## 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.
2019

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.
2221

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.
2823

2924
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.
3025

@@ -37,47 +32,96 @@ packages:
3732
3833
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.
3934
40-
```azurecli-interactive
41-
az group create --name myCentOSGroup --location eastus
35+
```azurecli-interactive
36+
az group create --name myResourceGroup --location eastus
4237
```
4338

4439
Now, create a VM with [az vm create](/cli/azure/vm) and specify the cloud-init file with the `--custom-data` parameter as follows:
4540

46-
```azurecli-interactive
41+
```azurecli-interactive
4742
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 \
5146
--custom-data cloud_init_upgrade.txt \
5247
--admin-username azureuser \
5348
--generate-ssh-keys
5449
```
5550

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:
5755

5856
```bash
59-
ssh azureuser@<publicIpAddress>
57+
ssh <user>@<publicIpAddress>
6058
```
6159

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
6365

6466
```bash
65-
sudo yum update
67+
sudo yum check-update
6668
```
6769

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.
6973

7074
```bash
75+
sudo yum history
76+
```
77+
78+
```output
7179
ID | Command line | Date and time | Action(s) | Altered
7280
--------------------------------------------------------------------------------------------------
7381
3 | -y install httpd | 2022-02-18 18:30 | Install | 7
7482
2 | -y upgrade | 2022-02-18 18:23 | I, O, U | 321 EE
7583
1 | | 2021-02-04 19:20 | Install | 496 EE
7684
```
7785

86+
# [Ubuntu](#tab/ubuntu)
87+
88+
- Execute the following command to confirm there are no pending updates
89+
90+
```bash
91+
sudo apt -qq update
92+
sudo apt list --upgradable
93+
```
94+
95+
As cloud-init checked for and installed updates on boot, there should be no additional updates to apply.
96+
97+
- You can see the update process and altered packages by running the following command and reviewing the output
98+
99+
```bash
100+
sudo cat /var/log/dpkg.log
101+
```
102+
103+
# [SLES](#tab/sles)
104+
105+
- Execute the following command to confirm there are no pending updates
106+
107+
```bash
108+
sudo zypper list-updates
109+
```
110+
111+
As cloud-init checked for and installed updates on boot, there should be no additional updates to apply.
112+
113+
- You can see the update process and altered packages by running the following command and reviewing the output
114+
115+
```bash
116+
sudo cat /var/log/zypp/history
117+
```
118+
119+
---
120+
78121
## Next steps
122+
79123
For additional cloud-init examples of configuration changes, see the following:
80-
124+
81125
- [Add an additional Linux user to a VM](cloudinit-add-user.md)
82126
- [Run a package manager to update existing packages on first boot](cloudinit-update-vm.md)
83127
- [Change VM local hostname](cloudinit-update-vm-hostname.md)

0 commit comments

Comments
 (0)