How to create ops-agents policy that will install ops-agent on all Ubuntu 22.04 VMs?

I have created this ops-agent policy to install ops-agent on all my running Ubuntu 22.04 VMs, but the policy exists in the Cloud console when I navigate to Monitoring → Dashboards → VM instances, it shows that it’s Legacy agent is installed (image below) and the agent seems uninstalled, what I’m missing here? what is the best way to install the ops agent automatically in any created VM managed by Instance Group?

gcloud beta compute instances ops-agents policies describe ops-agents-stag-policy --project=PROJECT-NAME
agent_rules:
- enable_autoupgrade: true
  package_state: installed
  type: ops-agent
  version: 2.*.*
assignment:
  group_labels:
  - env: PROJECT-NAME
    product: programs
  instances: []
  os_types:
  - short_name: ubuntu
    version: '22.04'
  zones:
  - europe-west1-b
create_time: '2024-02-14T13:23:07.226508Z'
description: A stag policy for programs.
etag: 0000000000000-ae63-468c-997f-0000000000000
id: projects/0000000000000/guestPolicies/ops-agents-stag-policy
update_time: '2024-02-14T13:23:07.226508Z'

Screenshot 2024-02-18 at 10.20.35 am.png

1 Like

https://www.googlecloudcommunity.com/gc/Infrastructure-Compute-Storage/Install-ops-agent-in-MIG-instances/m-p/434473
u can refer this

1 Like

I want to use project level police, which is the opposite of what that question is looking for.

1 Like

Hi,

Try this terraform module https://github.com/terraform-google-modules/terraform-google-cloud-operations/tree/master/modules/agent-policy

1 Like

This looks like a startup script and not a fleet policy.

1 Like

Use the module from README file https://github.com/terraform-google-modules/terraform-google-cloud-operations/blob/master/modules/agent-policy/README.md or check out this link https://registry.terraform.io/modules/terraform-google-modules/cloud-operations/google/latest/submodules/agent-policy

1 Like