Use OS Inventory Management to collect and view operating system details for your VM instances. These details include operating system 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:
- Enable guest attributes and the OS Inventory metadata keys on each instance or on the entire project.
- Install the OS Configuration agent on each instance.
After setting up OS Inventory Management on your VM instances, you can then view operating system details.
Before you begin
- If you want to use the command-line examples in this guide:
- Install or update to the latest version of the gcloud command-line tool.
- Set a default region and zone.
- If you want to use the API examples in this guide, set up API access.
Supported operating systems
OS Inventory Management is supported on the following operating systems:
- Debian 9
- Ubuntu 16.04 and 18.04
- CentOS 6 and 7
- Red Hat Enterprise Linux 6, 7, and 8
- Windows Server 2008R2, 2012R2, 2016, 2019 and semi-annual releases 1803 and 1809
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:
- In the Google Cloud Console, go to the VM Instances page.
- Click Create instance.
- On the Create a new instance page, fill in the desired properties for your instance.
In the Metadata section, add the following metadata entries:
enable-guest-attributes
and the value isTRUE
.enable-os-inventory
and the value isTRUE
.
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:
- Go to the Metadata page.
- Click Edit.
Add the following metadata entries:
enable-guest-attributes
and the value isTRUE
.enable-os-inventory
and the value isTRUE
.
Click Save to apply the changes.
Set enable-guest-attributes
and enable-os-inventory
in metadata of an existing instance:
- Go to the VM instances page.
- Click the name of the instance on which you want to set the metadata value.
- At the top of the instance details page, click Edit to edit the instance settings.
Under Custom metadata, add the following metadata entries:
enable-guest-attributes
and the value isTRUE
.enable-os-inventory
and the value isTRUE
.
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-oslogin metadata value 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:
gcloud compute project-info add-metadata \
--project [PROJECT_ID] \
--metadata=enable-guest-attributes=true,enable-os-inventory=true
where [PROJECT_ID]
is your project ID.
Set enable-guest-attributes
and enable-os-inventory
in metadata of an existing instance:
gcloud compute instances add-metadata [INSTANCE_NAME] \
--metadata=enable-guest-attributes=true,enable-os-inventory=true
where [INSTANCE_NAME]
is the name of the instance.
Set enable-guest-attributes
and enable-os-inventory
in instance metadata when you create an instance:
gcloud compute instances create [INSTANCE_NAME] \
--metadata=enable-guest-attributes=true,enable-os-inventory=true
where [INSTANCE_NAME]
is the name of the instance.
API
- For instructions on setting project-wide metadata, follow the API instructions for Setting project-wide custom metadata.
- For instructions on setting instance metadata, follow the API instructions for Setting instance metadata.
The following key-value pairs are required as your metadata values:
- Guest attributes:
- Key:
enable-guest-attributes
- Value:
True
- Key:
- OS Inventory Management:
- Key:
enable-os-inventory
- Value:
True
- Key:
Install the OS Configuration agent
On each instance, install the OS Configuration agent. You can install the OS Configuration agent by using one of the following options:
- Install the agent manually through the terminal.
- Use a startup script on your instances.
Installing the agent manually
Use this option to install the OS Configuration agent on an existing instance.
To install the agent, complete the following steps:
Connect to the instance that you want to install the OS Configuration agent on.
Install the OS Configuration agent.
Windows Server
To install the OS Configuration agent on a Windows server, run the following command:
googet -noconfirm install google-osconfig-agent
Ubuntu
Set up the Ubuntu repository.
sudo su -c "echo 'deb http://packages.cloud.google.com/apt google-osconfig-agent-stretch-stable main' > \ /etc/apt/sources.list.d/google-osconfig-agent.list" curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
Install the OS Configuration agent.
sudo apt-get update sudo apt-get install -y google-osconfig-agent
Debian
To install the OS Configuration agent on a Debian instance, run the following command:
sudo apt-get update sudo apt-get install -y google-osconfig-agent
If you get an
Unable to locate package
error message, you need to setup the Debian repository. To set up the Debian repository, run the following command:sudo su -c "echo 'deb http://packages.cloud.google.com/apt google-osconfig-agent-stretch-stable main' > \ /etc/apt/sources.list.d/google-osconfig-agent.list" curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
RHEL/CENTOS
To install the OS Configuration agent on a RHEL or CentOS instance, run the following command:
sudo yum -y install google-osconfig-agent
Installing the agent using a startup script
You can also use the manual installation commands to create a startup script that installs the OS Configuration agent during instance creation.
- Copy the manual commands for your operating system .
Provide the startup script to your instance creation method.
For example, if you are using the
gcloud compute instances create
command to create a new Debian 9 VM instance, your command would resemble the following:gcloud compute instances create INSTANCE_NAME \ --image-family=debian-9 --image-project=debian-cloud \ --metadata startup-script='#! /bin/bash sudo apt-get update sudo apt-get install -y google-osconfig-agent'
Verify that the startup script completes. To verify if the startup script completes, you can review the logs or check the serial console.
Viewing operating system details
Viewing inventory data
To view the inventory data for your instance, use the
instances os-inventory describe
command.
To view the inventory data collected for a VM, run the following command:
gcloud compute instances os-inventory describe [INSTANCE_NAME]
where [INSTANCE_NAME]
is the name of your instance.
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 n1-standard-1 192.0.2.1 RUNNING instance-inventory1 us-west1-b n1-standard-1 192.0.2.2 RUNNING instance-inventory2 asia-east2-b n1-standard-1 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 n1-standard-1 192.0.2.2 RUNNING instance-inventory2 asia-east2-b n1-standard-1 192.0.2.3 RUNNING
What's next
- Learn more about OS Inventory Management.