Viewing operating system details

This page describes how to set up and use OS inventory management. For an overview of OS inventory management, see OS inventory management.

Use OS inventory management to collect and view operating system details for your VM instances. These operating system details include information such as hostname, operating system, and kernel version as well as installed packages, and available package updates for the operating system. For a list of common scenarios for using OS inventory management, review When to use OS inventory management.

Before you can use OS inventory management, you need to configure your VM instances to use the feature. To configure your VM instances to use OS inventory management, you must complete the following procedures:

  1. Enable guest attributes and the OS Inventory metadata keys on each instance or on the entire project.
  2. Install the OS Config agent on each instance.

After setting up OS inventory management on your VM instances, you can then view operating system details.

Before you begin

Supported operating systems

For the full list of operating systems and versions that support OS inventory management, see Operating system details.

Enable guest attributes and OS inventory management

To enable guest attributes and OS inventory management you need to set some specific metadata keys.

To set custom metadata for an instance or project, you can use the Google Cloud Console, the gcloud command-line tool, or the Compute Engine API. You can set these attributes at the instance or project level.

Console

You can apply the metadata values on your projects or instances using one of the following options:

Set enable-guest-attributes and enable-os-inventory in instance metadata when you create an instance:

  1. In the Google Cloud Console, go to the VM Instances page.

    Go to the VM instances page

  2. Click Create instance.
  3. On the Create a new instance page, fill in the desired properties for your instance.
  4. In the Metadata section, add the following metadata entries:

    • enable-guest-attributes and the value is TRUE.
    • enable-os-inventory and the value is TRUE.
  5. Click Create to create the instance.

Set enable-guest-attributes and enable-os-inventory in project-wide metadata so that it applies to all of the instances in your project:

  1. Go to the Metadata page.

    Go to the Metadata page

  2. Click Edit.
  3. Add the following metadata entries:

    • enable-guest-attributes and the value is TRUE.
    • enable-os-inventory and the value is TRUE.
  4. Click Save to apply the changes.

Set enable-guest-attributes and enable-os-inventory in metadata of an existing instance:

  1. Go to the VM instances page.

    Go to the VM instances page

  2. Click the name of the instance on which you want to set the metadata value.
  3. At the top of the instance details page, click Edit to edit the instance settings.
  4. Under Custom metadata, add the following metadata entries:

    • enable-guest-attributes and the value is TRUE.
    • enable-os-inventory and the value is TRUE.
  5. At the bottom of the instance details page, click Save to apply your changes to the instance.

gcloud

Use the project-info add-metadata gcloud command to enable guest attributes and OS Inventory metadata keys.

You can apply the enable-guest-attributes and enable-os-inventory metadata values on your projects or instances using one of the following options:

Set enable-guest-attributes and enable-os-inventory in project-wide metadata so that it applies to all of the instances in your project. Replace project-id with your project ID.

gcloud compute project-info add-metadata \
    --project project-id \
    --metadata=enable-guest-attributes=true,enable-os-inventory=true

Set enable-guest-attributes and enable-os-inventory in metadata of an existing instance. Replace instance-name with the name of your instance.

gcloud compute instances add-metadata instance-name \
    --metadata=enable-guest-attributes=true,enable-os-inventory=true

Set enable-guest-attributes and enable-os-inventory in instance metadata when you create an instance. Replace instance-name with the name of your instance.

gcloud compute instances create instance-name \
    --metadata=enable-guest-attributes=true,enable-os-inventory=true

API

The following key-value pairs are required as your metadata values:

  • Guest attributes:
    • Key: enable-guest-attributes
    • Value: True
  • OS inventory management:
    • Key: enable-os-inventory
    • Value: True

Install the OS Config agent

On each instance, install the OS Config agent.

Viewing operating system details

Viewing inventory data

To view the inventory data for your instance, use the instances os-inventory describe command. Replace instance-name with the name of your instance.

To view the inventory data collected for a VM, run the following command:

gcloud compute instances os-inventory describe instance-name

To view the types of output details that is returned, review Information provided by OS inventory management.

Listing instances

To view the list of VM instances that have OS inventory management set up, run the instances os-inventory list-instances command.

For example, to list all the instances that have inventory data, run the following command:

gcloud compute instances os-inventory list-instances

Your output should resemble the following:

NAME                  ZONE        MACHINE_TYPE   PREEMPTIBLE  INTERNAL_IP  EXTERNAL_IP  STATUS
inventory-instance   us-east1-b    e2-standard-2               192.0.2.1                RUNNING
instance-inventory1  us-west1-b    e2-standard-2               192.0.2.2                RUNNING
instance-inventory2  asia-east2-b  e2-standard-2               192.0.2.3                RUNNING

You can also use filters to narrow down your results. For example, you can list all instances that have OS inventory management set up and whose hostname matches the regex instance-* by running the following command:

gcloud compute instances os-inventory list-instances --inventory-filter="Hostname~instance-*"

Your output should resemble the following:

NAME                  ZONE        MACHINE_TYPE   PREEMPTIBLE  INTERNAL_IP  EXTERNAL_IP  STATUS
instance-inventory1  us-west1-b    e2-standard-2               192.0.2.2                RUNNING
instance-inventory2  asia-east2-b  e2-standard-2               192.0.2.3                RUNNING

What's next