Skip to content

Commit 66507c5

Browse files
authored
Merge pull request #226946 from jasonmesser7/quick-create-cli-alterations
Altered the Linux VM quick create document to be more Linux and automation friendly
2 parents e6b7190 + 9bdc967 commit 66507c5

File tree

1 file changed

+72
-17
lines changed

1 file changed

+72
-17
lines changed

articles/virtual-machines/linux/quick-create-cli.md

Lines changed: 72 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,32 +29,44 @@ To open the Cloud Shell, just select **Try it** from the upper right corner of a
2929

3030
If you prefer to install and use the CLI locally, this quickstart requires Azure CLI version 2.0.30 or later. Run `az --version` to find the version. If you need to install or upgrade, see [Install Azure CLI]( /cli/azure/install-azure-cli).
3131

32+
## Define Environment Variables
33+
Environment variables are commonly used in Linux to centralize configuration data to improve consistency and maintainability of the system. Create the following environment variables to specify the names of resources that will be created later in this tutorial:
34+
35+
```azurecli-interactive
36+
export RESOURCE_GROUP_NAME=myResourceGroup
37+
export LOCATION=eastus
38+
export VM_NAME=myVM
39+
export VM_IMAGE=debian
40+
export ADMIN_USERNAME=azureuser
41+
```
42+
3243
## Create a resource group
3344

34-
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:
45+
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.
3546

3647
```azurecli-interactive
37-
az group create --name myResourceGroup --location eastus
48+
az group create --name $RESOURCE_GROUP_NAME --location $LOCATION
3849
```
3950

4051
## Create virtual machine
4152

4253
Create a VM with the [az vm create](/cli/azure/vm) command.
4354

44-
The following example creates a VM named *myVM* and adds a user account named *azureuser*. The `--generate-ssh-keys` parameter is used to automatically generate an SSH key, and put it in the default key location (*~/.ssh*). To use a specific set of keys instead, use the `--ssh-key-values` option.
55+
The following example creates a VM and adds a user account. The `--generate-ssh-keys` parameter is used to automatically generate an SSH key, and put it in the default key location (*~/.ssh*). To use a specific set of keys instead, use the `--ssh-key-values` option.
4556

4657
```azurecli-interactive
4758
az vm create \
48-
--resource-group myResourceGroup \
49-
--name myVM \
50-
--image Debian \
51-
--admin-username azureuser \
52-
--generate-ssh-keys
59+
--resource-group $RESOURCE_GROUP_NAME \
60+
--name $VM_NAME \
61+
--image $VM_IMAGE \
62+
--admin-username $ADMIN_USERNAME \
63+
--generate-ssh-keys \
64+
--public-ip-sku Standard
5365
```
5466

5567
It takes a few minutes to create the VM and supporting resources. The following example output shows the VM create operation was successful.
56-
57-
```output
68+
<!--expected_similarity=0.18-->
69+
```json
5870
{
5971
"fqdns": "",
6072
"id": "/subscriptions/<guid>/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM",
@@ -69,24 +81,31 @@ It takes a few minutes to create the VM and supporting resources. The following
6981

7082
Make a note of the `publicIpAddress` to use later.
7183

72-
## Install web server
84+
You can retrieve and store the IP address in the variable IP_ADDRESS with the following command:
85+
86+
```azurecli-interactive
87+
export IP_ADDRESS=$(az vm show --show-details --resource-group $RESOURCE_GROUP_NAME --name $VM_NAME --query publicIps --output tsv)
88+
```
89+
90+
[!INCLUDE [ephemeral-ip-note.md](../../../includes/ephemeral-ip-note.md)]
91+
92+
## Install web server
7393

74-
To see your VM in action, install the NGINX web server. Update your package sources and then install the latest NGINX package.
94+
To see your VM in action, install the NGINX web server. Update your package sources and then install the latest NGINX package. The following command uses run-command to run `sudo apt-get update && sudo apt-get install -y nginx` on the VM:
7595

7696
```azurecli-interactive
7797
az vm run-command invoke \
78-
-g myResourceGroup \
79-
-n myVM \
98+
--resource-group $RESOURCE_GROUP_NAME \
99+
--name $VM_NAME \
80100
--command-id RunShellScript \
81101
--scripts "sudo apt-get update && sudo apt-get install -y nginx"
82102
```
83-
84103
## Open port 80 for web traffic
85104

86105
By default, only SSH connections are opened when you create a Linux VM in Azure. Use [az vm open-port](/cli/azure/vm) to open TCP port 80 for use with the NGINX web server:
87106

88107
```azurecli-interactive
89-
az vm open-port --port 80 --resource-group myResourceGroup --name myVM
108+
az vm open-port --port 80 --resource-group $RESOURCE_GROUP_NAME --name $VM_NAME
90109
```
91110

92111
## View the web server in action
@@ -95,12 +114,48 @@ Use a web browser of your choice to view the default NGINX welcome page. Use the
95114

96115
![Screenshot showing the N G I N X default web page.](./media/quick-create-cli/nginix-welcome-page-debian.png)
97116

117+
Alternatively, run the following command to see the NGINX welcome page in the terminal
118+
119+
```azurecli-interactive
120+
curl $IP_ADDRESS
121+
```
122+
123+
The following example shows the default NGINX web site in the terminal as successful output:
124+
<!--expected_similarity=0.8-->
125+
```html
126+
<!DOCTYPE html>
127+
<html>
128+
<head>
129+
<title>Welcome to nginx!</title>
130+
<style>
131+
body {
132+
width: 35em;
133+
margin: 0 auto;
134+
font-family: Tahoma, Verdana, Arial, sans-serif;
135+
}
136+
</style>
137+
</head>
138+
<body>
139+
<h1>Welcome to nginx!</h1>
140+
<p>If you see this page, the nginx web server is successfully installed and
141+
working. Further configuration is required.</p>
142+
143+
<p>For online documentation and support please refer to
144+
<a href="http://nginx.org/">nginx.org</a>.<br/>
145+
Commercial support is available at
146+
<a href="http://nginx.com/">nginx.com</a>.</p>
147+
148+
<p><em>Thank you for using nginx.</em></p>
149+
</body>
150+
</html>
151+
```
152+
98153
## Clean up resources
99154

100155
When no longer needed, you can use the [az group delete](/cli/azure/group) command to remove the resource group, VM, and all related resources.
101156

102157
```azurecli-interactive
103-
az group delete --name myResourceGroup
158+
az group delete --name $RESOURCE_GROUP_NAME --no-wait --yes --verbose
104159
```
105160

106161
## Next steps

0 commit comments

Comments
 (0)