Set osDisk size when deploying a VM in Azure

If you need a larger OS disk, at deployment, for your VM you can add {“diskSizeGB”: integer} under osDisk in an ARM deployment template. This is an easy way to increase the size of the OS disk when creating a VM.

Below is an example from an ARM deployment template for an Ubuntu VM.

"storageProfile": {
                    "osDisk": {
                        "createOption": "fromImage",
                        "diskSizeGB": 512,
                        "managedDisk": {
                            "storageAccountType": "[parameters('osDiskType')]"
                        }
                    },

For more information and example visit: https://docs.microsoft.com/en-us/azure/templates/microsoft.compute/virtualmachines

Add a Tag when creating an Azure Resource Group

I have an Azure Automation Runbook, see post Clean up Azure Resource Groups with a Tag, that deletes Azure Resource Groups every night based on a tag.

Instead of typing the tag name every time, when creating new Resource Groups, I use a script that adds the tag and the location of the Resource Group.

To use the script, use Azure Cli in Azure or on a Linux host by running:

.\create_resourcegroup_with_tag.sh -g myrg

Download the script from GitHub or copy it from below.

# Creates a resource group with a tag
# Example: .\create_resourcegroup_with_tag.sh -g myrg

# Variables to be set when creating the resource group
location="westeurope"
tagname="RemoveResourceGroup"
tagvalue="Yes"

# input section
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"

case $key in
    -g|--resourcegroup)
    rg="$2"
    shift
    shift
    ;;
    -h|--help)
    echo "Please add -g for Resource Group Name" >&2; exit 1
    ;;
    -*) echo "unknown option: $1" >&2; exit 1;;
    *) handle_argument "$1"; shift 1;;
esac
done

if [ "$rg" == "" ]
    then
        echo "Missing argument Resource Group Name"
        exit 1
fi

az group create -n "$rg" -l "$location" --tag "$tagname"="$tagvalue"

Disable access for everyone to the Azure Red Hat OpenShift portal

When creating an Azure Red Hat OpenShift (ARO) cluster you will notice that everyone with an AAD account will have access to the portal and to create a project. If you would like to disable this behavior and only let certain users to access ARO you can do this by edit the ARO Enterprise Application in AAD.

Under properties change “User assignment required” to “Yes”. Then populate the “Users and groups” on the Enterprise Application with the users that should have access to the ARO portal.

/usr/bin/python: No module named azure

If you get the message “/usr/bin/python: No module named azure” when running the az command in a Linux VM where you have installed azure-cli. Your problem could be that you are using an old version of Python.

Check what Python version is used with the command: python -V

If using an old Python version, install a newer. Check documentation how to update the Python version at your system. At the time of writing I am using 3.2.8.
After the installation check the bin directory for Python using the command:
ls -l /usr/bin/python*

To change for a new Python version, you need to remove and create a new link. Use the following command:
sudo rm /usr/bin/python
sudo ln -s /usr/bin/python3 /usr/bin/python

Check what version is used after creating a new link. Command:
python -V

Send data to OMS Log Analytics with Curl from a Linux server

Here is an example how to send data to OMS Log Analytics with Curl from a Linux server. I have created a bash script that creates everything that is needed for Curl to send data to OMS Log Analytics. Just add your Workspace ID and Workspace Key and try it out. Hope it is useful for you!

Save the following script, make the changes necessary and then run it.

#!/bin/bash
LANG=en_us_8859_1

# Update the customer ID to your Operations Management Suite workspace ID
ws="workspaceid"

# For the shared key, use either the primary or the secondary Connected Sources client authentication key
key='workspacekey'

# Name of the log generated
LogType='LinuxCurl'

data='{"LinuxCurlId":"001","LinuxCurlValue1":"value1"}'

timestamp=$(date -u +"%a, %d %b %Y %H:%M:%S GMT")

stringToSign=$(echo -e "POST\n${#data}\napplication/json\nx-ms-date:${timestamp}\n/api/logs")

decodedkey=`printf %s "$key" | base64 -d`

encodedHash=`printf %s "$stringToSign" | openssl dgst -sha256 -binary -hmac "$decodedkey" | sed 's/^.* //' | base64`

Signature="SharedKey $ws:$encodedHash"

curl -H "Content-Type:application/json" -d "${data}" "https://${ws}.ods.opinsights.azure.com/api/logs?api-version=2016-04-01" -H "x-ms-date:${timestamp}" -H "Log-Type:${LogType}" -H "Authorization:${Signature}" -v

The first time you run the script OMS Log Analytics will create Custom Fields for you based on your data input.

Send data to OMS Log Analytics with Curl from a Linux server1

After some time, you will see the first data from your script. As for now, the data record will not be complete from the beginning. But after some time, the data record  will be updated and all information will be shown. When you see the full data record, all the following record will have all information from the beginning without any delay.

Send data to OMS Log Analytics with Curl from a Linux server2

To get more information, please have a look at Microsoft documentation – https://docs.microsoft.com/en-us/azure/log-analytics/log-analytics-data-collector-api