Last active
February 28, 2024 13:32
-
-
Save BretStateham/4703e5fdedd5301dd1bb30a951cc06cb to your computer and use it in GitHub Desktop.
Create an Ubuntu 18.04 VM in Azure and provision it with the Azure CLI, Moby and the Azure IoT Edge Runtime using Cloud-Init
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#cloud-config | |
apt_sources: | |
- source: "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ bionic main" | |
key: | | |
-----BEGIN PGP PUBLIC KEY BLOCK----- | |
Version: GnuPG v1.4.7 (GNU/Linux) | |
mQENBFYxWIwBCADAKoZhZlJxGNGWzqV+1OG1xiQeoowKhssGAKvd+buXCGISZJwT | |
LXZqIcIiLP7pqdcZWtE9bSc7yBY2MalDp9Liu0KekywQ6VVX1T72NPf5Ev6x6DLV | |
7aVWsCzUAF+eb7DC9fPuFLEdxmOEYoPjzrQ7cCnSV4JQxAqhU4T6OjbvRazGl3ag | |
OeizPXmRljMtUUttHQZnRhtlzkmwIrUivbfFPD+fEoHJ1+uIdfOzZX8/oKHKLe2j | |
H632kvsNzJFlROVvGLYAk2WRcLu+RjjggixhwiB+Mu/A8Tf4V6b+YppS44q8EvVr | |
M+QvY7LNSOffSO6Slsy9oisGTdfE39nC7pVRABEBAAG0N01pY3Jvc29mdCAoUmVs | |
ZWFzZSBzaWduaW5nKSA8Z3Bnc2VjdXJpdHlAbWljcm9zb2Z0LmNvbT6JATUEEwEC | |
AB8FAlYxWIwCGwMGCwkIBwMCBBUCCAMDFgIBAh4BAheAAAoJEOs+lK2+EinPGpsH | |
/32vKy29Hg51H9dfFJMx0/a/F+5vKeCeVqimvyTM04C+XENNuSbYZ3eRPHGHFLqe | |
MNGxsfb7C7ZxEeW7J/vSzRgHxm7ZvESisUYRFq2sgkJ+HFERNrqfci45bdhmrUsy | |
7SWw9ybxdFOkuQoyKD3tBmiGfONQMlBaOMWdAsic965rvJsd5zYaZZFI1UwTkFXV | |
KJt3bp3Ngn1vEYXwijGTa+FXz6GLHueJwF0I7ug34DgUkAFvAs8Hacr2DRYxL5RJ | |
XdNgj4Jd2/g6T9InmWT0hASljur+dJnzNiNCkbn9KbX7J/qK1IbR8y560yRmFsU+ | |
NdCFTW7wY0Fb1fWJ+/KTsC4= | |
=J6gs | |
-----END PGP PUBLIC KEY BLOCK----- | |
- source: "deb [arch=amd64] https://packages.microsoft.com/ubuntu/18.04/prod bionic main" | |
package_upgrade: true | |
packages: | |
- apt-transport-https | |
- ca-certificates | |
- curl | |
- software-properties-common | |
- moby-engine | |
- moby-cli | |
- azure-cli | |
runcmd: | |
- usermod -aG docker hacker | |
- az extension add --name azure-cli-iot-ext | |
- apt-get install iotedge -y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# You need to have the Azure CLI installed on your machine. You can get it from here: | |
# https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest | |
# | |
# This script can be run on Linux, Mac OS, or the Windows Subsystem for Linux (WSL) | |
# | |
# ensure you are logged into the azure cli | |
# az login | |
# | |
# ensure you are using the desired subscription | |
# az account list | |
# az account set | |
# az account show | |
# | |
# Set these variables to your desires | |
resourceGroupName=ohtsanramon-RG-VMs | |
location=westus | |
vmName=edgevm | |
userName=hacker | |
password=P@ssw1rd1234 | |
# | |
# Optionally set these variables | |
# You can get an up to date list of available ubuntu images by running | |
# az vm image list -p Canonical --all -o table | |
# | |
# And make sure you have the .yaml file downloaded. | |
# You can get it from here: | |
# https://gist.github.com/BretStateham/4703e5fdedd5301dd1bb30a951cc06cb/raw/dedf4e2acdfaec6e56b90934cecb37693e6d7818/cloud-init-azmobyedge-bionic.yaml | |
# | |
ubuntuImage=Canonical:UbuntuServer:18.04-LTS:18.04.201809110 | |
cloudInitPath=cloud-init-azmobyedge-bionic.yaml | |
az group create -n $resourceGroupName -l $location | |
az vm create -n $vmName -g $resourceGroupName --image $ubuntuImage --authentication-type password --admin-username $userName --admin-password $password --custom-data $cloudInitPath | |
ipAddress=$(az vm list-ip-addresses -g ohtsanramon-RG-VMs -n edgevm --query [0].virtualMachine.network.publicIpAddresses[0].ipAddress -o tsv) | |
echo | |
echo ------------------------------------------------------------------------------ | |
echo | |
echo Your VM has been created with these options: | |
echo | |
echo Resource Group: $resourceGroupName | |
echo Location: $location | |
echo VM Name: $vmName | |
echo IP Address: $ipAddress | |
echo User Name: $userName | |
echo Password: $password | |
echo Ubuntu Image: $ubuntuImage | |
echo | |
echo | |
echo Please wait a few minutes before attaching to allow the installations of the Azure CLI, Moby and the IoT Edge Runtime to complete. | |
echo | |
echo You will need to edit the /etc/iotedge/config.yaml file to configure your iotedge device connection | |
echo See the following page for more details: | |
echo https://docs.microsoft.com/en-us/azure/iot-edge/how-to-install-iot-edge-linux#option-1-manual-provisioning | |
echo | |
echo You can ssh into your vm using: | |
echo | |
echo ssh $userName@$ipAddress | |
echo | |
echo With the password: | |
echo | |
echo $password | |
echo | |
echo -------------------------------------------------------------------------------- | |
echo |
For anybody who also find this.
This is my cloud-config for ubuntu 22
#cloud-config
apt:
sources:
az.list:
source: deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli $RELEASE main
keyid: BC528686B50D79E339D3721CEB3E94ADBE1229CF
docker.list:
source: deb [arch=amd64] https://download.docker.com/linux/ubuntu $RELEASE stable
keyid: 9DC858229FC7DD38854AE2D88D81803C0EBFCD88
ubunut-ms.list:
source: deb [arch=amd64] https://packages.microsoft.com/ubuntu/22.04/prod $RELEASE main
keyid: BC528686B50D79E339D3721CEB3E94ADBE1229CF
packages:
- azure-cli
- docker-ce
- docker-ce-cli
- powershell
- unzip # required for TerraformInstaller task
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great gist - thanks for sharing!
The apt-get list can now be simplified with the following: