# Step 1: Generate an SSH key in Pipeline
- script: |
ssh-keygen -t rsa -b 2048 -f ~/.ssh/id_rsa -q -N ""
# Step 2. Automatically create an Azure Linux VM with an SSH key
- task: AzureCLI@2
inputs:
azureSubscription: '<SUBSCRIPTION>'
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: |
az vm create \
--resource-group myResourceGroup \
--name myVM \
--image UbuntuLTS \
--admin-username azureuser \
--ssh-key-values ~/.ssh/id_rsa.pub
# Step 3. Obtain IP and auto-configuration via SSH
- task: AzureCLI@2
inputs:
azureSubscription: '<SUBSCRIPTION>'
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: |
vm_ip=$(az vm show -d -g myResourceGroup -n myVM --query publicIps -o tsv)
ssh -o StrictHostKeyChecking=no azureuser@$vm_ip << EOF
sudo apt-get update
sudo apt-get install -y nginx
echo "Hello from Azure DevOps!" | sudo tee /var/www/html/index.html
EOF