- NAME
- 
- gcloud beta compute instances ops-agents policies update - update a Google Cloud operations suite agent (Ops Agent) policy
 
- SYNOPSIS
- 
- 
gcloud beta compute instances ops-agents policies updatePOLICY_ID[--agent-rules=type=TYPE,version=VERSION,package-state=PACKAGE-STATE,enable-autoupgrade=ENABLE-AUTOUPGRADE;[…]] [--description=DESCRIPTION] [--etag=ETAG] [--os-types=short-name=SHORT-NAME,version=VERSION;[…]] [--clear-group-labels|--group-labels=[LABEL_NAME=LABEL_VALUE,LABEL_NAME=LABEL_VALUE,…;…]] [--clear-instances|--instances=[zones/ZONE_NAME/instances/INSTANCE_NAME,…]] [--clear-zones|--zones=[ZONE_NAME,…]] [GCLOUD_WIDE_FLAG …]
 
- 
- DESCRIPTION
- 
(BETA)gcloud beta compute instances ops-agents policies updateupdates a policy that facilitates agent management across Compute Engine instances based on user specified instance filters. This policy installs, specifies versioning, enables autoupgrade, and removes Ops Agents.The command returns the content of the updated policy or an error indicating why the update fails. The updated policy takes effect asynchronously. It can take 10-15 minutes for the VMs to enforce the updated policy. The available flags for the updatecreateupdateupdate--agentsIf the original policy specified two agents ( --agents="type=logging;type=metrics"--agents="type=logging"gcloud beta compute instances ops-agents policies updatecommand, then the policy stops managing and enforcing the unspecified agent. In order to remove the metrics agent in this case, set the package state explicitly toremoved--agents="type=logging;type=metrics,package-state=removed"In order to explicitly clear the --group-labels--instances--zones--clear-group-labels--clear-instances--clear-zones
- EXAMPLES
- 
To update a policy named
ops-agents-test-policyzones/us-central1-a/instances/test-instancegcloud beta compute instances ops-agents policies update ops-agents-test-policy --agent-rules="type=logging,enable-autoupgrade=false;type=metrics,enable-autoupgrade=false" --instances=zones/us-central1-a/instances/test-instance --os-types=short-name=centos,version=7To update a policy named ops-agents-prod-policyus-central1-aenv=prod,product=myappenv=staging,product=myappgcloud beta compute instances ops-agents policies update ops-agents-prod-policy --agent-rules="type=logging,version=1.*.*,enable-autoupgrade=false;type=metrics,version=6.*.*,enable-autoupgrade=false" --group-labels="env=prod,product=myapp;env=staging,product=myapp" --os-types=short-name=centos,version=7 --zones=us-central1-aTo update a policy named ops-agents-labels-policyenv=prod,product=myappenv=staging,product=myappgcloud beta compute instances ops-agents policies update ops-agents-labels-policy --clear-instances --group-labels="env=prod,product=myapp;env=staging,product=myapp"To perform the same update as above, conditionally on the fact that the policy's etag (retrieved by an earlier command) is f59741c8-bb5e-4ee6-bf6f-c4ebeb6b06e0gcloud beta compute instances ops-agents policies update ops-agents-labels-policy --clear-instances --group-labels="env=prod,product=myapp;env=staging,product=myapp" --etag=f59741c8-bb5e-4ee6-bf6f-c4ebeb6b06e0
- POSITIONAL ARGUMENTS
- 
- POLICY_ID
- 
ID of the policy.
This ID must start with ops-agents-ops-agents-
 
- FLAGS
- 
- --agent-rules=- type=- TYPE,- version=- VERSION,- package-state=- PACKAGE-STATE,- enable-autoupgrade=- ENABLE-AUTOUPGRADE;[…]
- 
A non-empty list of agent rules to be enforced by the policy.
This flag must be quoted. Items in the list are separated by ";". Each item in the list is a <key, value> map that represents a logging or metrics agent. The allowed values of the key are as follows. - type
- 
Type of agent to manage.
Required. Allowed values:loggingmetricsops-agentloggingmetricsops-agentops-agent
- enable-autoupgrade
- 
Whether to enable autoupgrade of the agent.
Required. Allowed values:truefalsefalseversion=MAJOR_VERSION.MINOR_VERSION.PATCH_VERSION
- version
- 
Version of the agent to install.
Optional. Default to version=current-major- version=latest
- 
With this setting, the latest version of the agent is installed at the time when
the policy is applied to an instance.
If multiple instances are created at different times but they all fall into the instance filter rules of an existing policy, they may end up with different versions of the agent, depending on what the latest version of the agent is at the policy application time (in this case the instance creation time). One way to avoid this is to set enable-autoupgrade=trueWhile this version=latestversion=MAJOR_VERSION.*.*setting below for safer agent deployments.
- version=MAJOR_VERSION.*.*
- 
With this setting, the latest version of agent from a specific major version is
installed at the time when the policy is applied to an instance.
If multiple instances are created at different times but they all fall into the instance filter rules of an existing policy, they may end up with different versions of the agent, depending on what the latest version of the agent is at the policy application time (in this case the instance creation time). One way to avoid this is to set enable-autoupgrade=trueWhen a new major release is out, this setting ensures that only the latest version from the specified major version is installed, which avoids accidentally introducing breaking changes. This is recommended for production environments to ensure safer agent deployments. 
- version=current-major
- 
With this setting, the version field is automatically set to
version=MAJOR_VERSION.*.*, whereMAJOR_VERSIONversion=MAJOR_VERSION.*.*section for the expected behavior.
- version=MAJOR_VERSION.MINOR_VERSION.PATCH_VERSION
- 
With this setting, the specified exact version of agent is installed at the time
when the policy is applied to an instance.
enable-autoupgradeThis setting is not recommended since it prevents the policy from installing new versions of the agent that include bug fixes and other improvements. One limitation of this setting is that if the agent gets manually uninstalled from the instances after the policy gets applied, the policy can only ensure that the agent is re-installed. It is not able to restore the expected exact version of the agent. 
- version=5.5.2-BUILD_NUMBER
- 
Allowed for the metrics agent
(type=metricsWith this setting, the specified exact build number of the deprecated 5.5.2 metrics agent is installed at the time when the policy is applied to an instance. enable-autoupgrade must be false for this setting. This setting is deprecated and will be decommissioned along with the 5.5.2 metrics agent on Apr 28, 2021 (https://cloud.google.com/stackdriver/docs/deprecations/mon-agent). It is not recommended since it prevents the policy from installing new versions of the agent that include bug fixes and other improvements. One limitation of this setting is that if the agent gets manually uninstalled from the instances after the policy gets applied, the policy can only ensure that the agent is re-installed. It is not able to restore the expected exact version of the agent. 
 
- package-state
- 
Desired package state of the agent.
Optional. Default to package-state=installed- package-state=installed
- With this setting, the policy will ensure the agent package is installed on the instances and the agent service is running.
- package-state=removed
- With this setting, the policy will ensure the agent package is removed from the instances, which stops the service from running.
 
 
- --description=- DESCRIPTION
- Description of the policy.
- --etag=- ETAG
- 
Etag of the policy.
etagetagetagdescribeetagupdate
- --os-types=- short-name=- SHORT-NAME,- version=- VERSION;[…]
- 
A non-empty list of OS types to filter instances that the policy applies to.
For Alpha and Beta, exactly one OS type needs to be specified. The support for multiple OS types will be added later for more flexibility. Each OS type is defined by the combination of short-nameversionSample values: OS Short Name OS Version centos 8 centos 7 debian 12 debian 11 debian 10 debian 9 rhel 9.* rhel 8.* rhel 7.* rocky 9.* rocky 8.* sles 12.* sles 15.* sles_sap 12.* sles_sap 15.* ubuntu 16.04 ubuntu 18.04 ubuntu 19.10 ubuntu 20.04 ubuntu 21.04 ubuntu 21.10 ubuntu 22.04 ubuntu 23.04 ubuntu 23.10 ubuntu 24.04 ubuntu 24.10 windows 10.* windows 6.* - short-name
- 
Short name of the OS.
Required. Allowed values:centosdebianrhelrockyslessles_sapubuntuTo inspect the exact OS short name of an instance, run: gcloud beta compute instances os-inventory describe INSTANCE_NAME | grep "^ShortName: "Under the hood, this value is derived from the ID/etc/os-release
- version
- 
Version of the OS.
Required. This can be either an exact match or a prefix followed by the*wildcard.To inspect the exact OS version of an instance, run: gcloud beta compute instances os-inventory describe INSTANCE_NAME | grep "^Version: "Under the hood, this value is derived from the VERSION_ID/etc/os-release
 
- 
At most one of these can be specified:
- --clear-group-labels
- 
Clear the group labels filter that was previously set by the
--group-labels
- --group-labels=[- LABEL_NAME=- LABEL_VALUE,- LABEL_NAME=- LABEL_VALUE,…;…]
- 
A list of label maps to filter instances that the policy applies to.
Optional. The --group-labels;. To manage instance labels, refer to:gcloud beta compute instances add-labelsgcloud beta compute instances remove-labelsEach label map item in the --group-labelsLABEL_NAME=LABEL_VALUE,LABEL_NAME=LABEL_VALUE,…LABEL_NAME=LABEL_VALUE--group-labelsFor example, --group-labels="env=prod,product=myapp;env=staging,product=myapp"(env=prod AND product=myapp) OR (env=staging AND product=myapp)
 
- 
At most one of these can be specified:
- --clear-instances
- 
Clear the instances filter that was previously set by the
--instances
- --instances=[- zones/- ZONE_NAME/- instances/- INSTANCE_NAME,…]
- 
A list of fully-qualified names to filter instances that the policy applies to.
Each item in the list must be in the format of zones/ZONE_NAME/instances/INSTANCE_NAME. The policy can also target instances that are not yet created.To list all existing instances, run: gcloud compute instances listThe --instances--zones--group-labels
 
- 
At most one of these can be specified:
- --clear-zones
- 
Clear the zones filter that was previously set by the
--zones
- --zones=[- ZONE_NAME,…]
- 
A list of zones to filter instances to apply the policy.
To list available zones, run: gcloud compute zones listThe use of the --zones--group-labels--instances
 
 
- GCLOUD WIDE FLAGS
- 
These flags are available to all commands: --access-token-file,--account,--billing-project,--configuration,--flags-file,--flatten,--format,--help,--impersonate-service-account,--log-http,--project,--quiet,--trace-token,--user-output-enabled,--verbosity.Run $ gcloud helpfor details.
- NOTES
- 
This command is currently in beta and might change without notice. These
variants are also available:
gcloud compute instances ops-agents policies updategcloud alpha compute instances ops-agents policies update
      gcloud beta compute instances ops-agents policies update
  
  
  Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-07-22 UTC.