Forge Home

azuremetadata

This Puppet module exposes the Azure instance metadata as facts

26,871 downloads

6,983 latest version

5.0 quality score

We run a couple of automated
scans to help you access a
module's quality. Each module is
given a score based on how well
the author has formatted their
code and documentation and
modules are also checked for
malware using VirusTotal.

Please note, the information below
is for guidance only and neither of
these methods should be considered
an endorsement by Puppet.

Version information

  • 0.2.0 (latest)
  • 0.1.9
  • 0.1.8
  • 0.1.7
  • 0.1.6
  • 0.1.5
  • 0.1.4
  • 0.1.3
  • 0.1.2
  • 0.1.1
  • 0.1.0
  • 0.0.2 (deleted)
  • 0.0.1 (deleted)
released Aug 14th 2020
This version is compatible with:
  • Puppet Enterprise 2019.8.x, 2019.7.x, 2019.5.x, 2019.4.x, 2019.3.x, 2019.2.x, 2019.1.x, 2019.0.x, 2018.1.x
  • Puppet >= 5.5.20 < 7.0.0
  • RedHat, Windows

Start using this module

  • r10k or Code Manager
  • Bolt
  • Manual installation
  • Direct download

Add this module to your Puppetfile:

mod 'keirans-azuremetadata', '0.2.0'
Learn more about managing modules with a Puppetfile

Add this module to your Bolt project:

bolt module add keirans-azuremetadata
Learn more about using this module with an existing project

Manually install this module globally with Puppet module tool:

puppet module install keirans-azuremetadata --version 0.2.0

Direct download is not typically how you would use a Puppet module to manage your infrastructure, but you may want to download the module in order to inspect the code.

Download

Documentation

keirans/azuremetadata — version 0.2.0 Aug 14th 2020

azuremetadata

Table of Contents

  1. Description
  2. Setup
  3. Usage
  4. Limitations
  5. Development

Description

Azure now has an instance metadata service that is GA globally !

To help with further automation, this modules exposes the Azure instance metadata as a structured fact for use in Puppet code. If you would like to see this end up in Facter Core, please do vote for the JIRA below:

This has been tested with Puppet 6.17.0 RHEL8 , however it should work on any platform that has a modern Ruby with open-uri and JSON support.

This module was part of a larger part of Puppet and Azure work that I presented at Puppetconf 2017.

Setup

What azuremetadata affects

This module deploys a single Ruby file that queries and exposes the Azure metadata as a structured fact.

Setup Requirements

Include the module in your Puppetfile and let pluginsync do the rest for you.

Puppetfile entries

# Directly from Git
mod 'azuremetadata',
    :git => 'https://github.com/keirans/azuremetadata.git',
    :tag => '0.2.0'


# Directly from the forge
mod 'keirans-azuremetadata', '0.2.0'

Usage

Once the fact is in place, you can use Facter on your Windows and Linux nodes to access the values as follows:

Returning the full set of metadata from Facter on Windows

PS> facter az_metadata
{
  compute => {
    azEnvironment => "AzurePublicCloud",
    customData => "",
    isHostCompatibilityLayerVm => "false",
    location => "australiasoutheast",
    name => "puppetdev",
    offer => "RHEL",
    osType => "Linux",
    placementGroupId => "",
    plan => {
      name => "",
      product => "",
      publisher => ""
    },
    platformFaultDomain => "0",
    platformUpdateDomain => "0",
    provider => "Microsoft.Compute",
    publicKeys => [
      {
        keyData => "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC7OGhS/PGV7Ov6071BmaE2JnZs1J32zzdzkJD8Np6+1Uz/d7wFUHn4X76jbNlFJ78U5nr/i7WINmZ/rPkw+sLby/u95pwCeL28MiGvZWR7TKuRGb3QJTkWIoRUkJ6AH6IBMMoAbfwVlgEwP2nArJI4QS+euy7uHZONeYGXxUUsw37UYGtRHM+m62yURB8ZsNEzssMSu1/OLb5322RGubxFaT9QMOhaUcfvtCuO6MN3DmIuHCr9dlQV/c8HzztGW9YlMCd2Dcvbp9w+LcPYldGw/U8JVF+K2YHLKxBa5ZlB3+jC0KJG3HCnj+TJ2tc+MsLprdh5oCom/Mi3l/XOmpEr keiran@Keirans-MacBook-Pro.local",
        path => "/home/keiran/.ssh/authorized_keys"
      }
    ],
    publisher => "RedHat",
    resourceGroupName => "puppetdev_group",
    resourceId => "/subscriptions/0432b1d0-5e2e-4e2a-ad73-e33d0652e3f7/resourceGroups/puppetdev_group/providers/Microsoft.Compute/virtualMachines/puppetdev",
    securityProfile => {
      secureBootEnabled => "false",
      virtualTpmEnabled => "false"
    },
    sku => "82gen2",
    storageProfile => {
      dataDisks => [],
      imageReference => {
        id => "",
        offer => "RHEL",
        publisher => "RedHat",
        sku => "82gen2",
        version => "latest"
      },
      osDisk => {
        caching => "ReadWrite",
        createOption => "FromImage",
        diffDiskSettings => {
          option => ""
        },
        diskSizeGB => "64",
        encryptionSettings => {
          enabled => "false"
        },
        image => {
          uri => ""
        },
        managedDisk => {
          id => "/subscriptions/0432b1d0-5e2e-4e2a-ad73-e33d0652e3f7/resourceGroups/PUPPETDEV_GROUP/providers/Microsoft.Compute/disks/puppetdev_OsDisk_1_62a017170f4044adbcfea54cea6cc45d",
          storageAccountType => "Premium_LRS"
        },
        name => "puppetdev_OsDisk_1_62a017170f4044adbcfea54cea6cc45d",
        osType => "Linux",
        vhd => {
          uri => ""
        },
        writeAcceleratorEnabled => "false"
      }
    },
    subscriptionId => "0432b1d0-5e2e-4e2a-ad73-e33d0652e3f7",
    tags => "testtag1:thisisavalue1;testtag:2:thisisavalue2",
    tagsList => [
      {
        name => "testtag1",
        value => "thisisavalue1"
      },
      {
        name => "testtag:2",
        value => "thisisavalue2"
      }
    ],
    version => "8.2.2020050812",
    vmId => "976f831c-dc8d-446d-b62d-0598b77b5799",
    vmScaleSetName => "",
    vmSize => "Standard_D4s_v3",
    zone => ""
  },
  network => {
    interface => [
      {
        ipv4 => {
          ipAddress => [
            {
              privateIpAddress => "10.5.0.4",
              publicIpAddress => "52.189.236.160"
            }
          ],
          subnet => [
            {
              address => "10.5.0.0",
              prefix => "24"
            }
          ]
        },
        ipv6 => {
          ipAddress => []
        },
        macAddress => "00224814BABC"
      }
    ]
  }
}

Returning individual values of the metadata from Facter on Windows

PS> facter  az_metadata.compute.location
australiasoutheast
PS>

You can then reference these values in your Puppet code using the facts hash such as:

notice("The  Azure location for ${facts['networking']['fqdn']} is ${facts['az_metadata']['compute']['location']}")

Limitations

API version pinned to 2020-06-01

Version 0.2.0 is currently using API version 2020-06-01, I'll update this as new versions become available and bump the module version accordingly.

Please note that versions prior to 0.2.0 introduced a 'tags' key in the fact data, this now conflicts with a value in the metadata data itself from the Azure platform, as such it has been removed and you should use the tagsList value instead which is native functionaly. As a result, 0.2.0 is a breaking change for previous users.

This native approach also gracefully handles special characters in tag keys and values unlike previous versions of the module.

# facter  az_metadata.compute.tags
testtag1:thisisavalue1;testtag:2:thisisavalue2
# facter az_metadata.compute.tagsList
[
  {
    name => "testtag1",
    value => "thisisavalue1"
  },
  {
    name => "testtag:2",
    value => "thisisavalue2"
  }
]
#

Development

I'm no longer actively using Azure anymore, so updates can be a bit delayed, however I'm still Happy to accept pull requests, if you could make them easier for me to merge, that would be amazing, specifically ensuring that fixes bump the version number, update the metadata file and also the README so i don't have to. :) :) :)

I'd expect this to end up in Facter Core at some time in the future, then this can be deprecated.

Please do vote for this JIRA for its addition: