Open project-oagent-gh-app[bot] opened 1 month ago
Below is a bash script that creates files required for the task.
#!/bin/bash
# Create a cloud-init configuration file
echo "#cloud-config
package_upgrade: true
packages:
- nginx" > cloud-init.txt
# Create a script for the Azure CLI commands
echo "#!/bin/bash
# Create a resource group
az group create --name myResourceGroupAutomate --location eastus
# Create a VM
az vm create \
--resource-group myResourceGroupAutomate \
--name myAutomatedVM \
--image UbuntuLTS \
--admin-username azureuser \
--generate-ssh-keys \
--custom-data cloud-init.txt
# Install Nginx using Azure CLI
az vm extension set \
--resource-group myResourceGroup \
--vm-name myVM --name customScript \
--publisher Microsoft.Azure.Extensions \
--settings '{\"commandToExecute\": \"apt-get install -y nginx\"}'" > azure-cli-commands.sh
# Make the Azure CLI script executable
chmod +x azure-cli-commands.sh
echo "Files 'cloud-init.txt' and 'azure-cli-commands.sh' created successfully."
This bash script creates two files: cloud-init.txt
and azure-cli-commands.sh
. The cloud-init.txt
file is a cloud-init configuration that updates the packages on the VM and installs Nginx. The azure-cli-commands.sh
file contains Azure CLI commands to create a resource group, create a VM in that resource group, and install Nginx on the VM.
The script then makes the azure-cli-commands.sh
file executable using the chmod
command, so it can be run directly. On running this bash script, it will output a message saying that the files were created successfully.
{ 'code': "# Install Azure CLI curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
Install .Net Core SDK
wget https://download.visualstudio.microsoft.com/download/pr/95e91e8e-496e-4f22-8d12-573aa5aa67f6/32cc5f113a3a10f6e6c4d8a4e2d6f203/dotnet-sdk-3.1.100-preview3-014645-linux-x64.tar.gz mkdir -p $HOME/dotnet && tar zxf dotnet-sdk-3.1.100-preview3-014645-linux-x64.tar.gz -C $HOME/dotnet export DOTNET_ROOT=$HOME/dotnet export PATH=$PATH:$HOME/dotnet" }