A Google Compute Engine (GCE) instance ($GCE_INSTANCE_NAME) was just created within a Google Cloud Platform (GCP) project $GCP_PROJECT_ID. There is an OSConfig guest policy ($GUEST_POLICY_NAME) that is supposed to install guest software packages onto $GCE_INSTANCE_NAME; however, when the Cloud SDK (gcloud) is used to lookup the guest policies applied to $GCE_INSTANCE_NAME:
gcloud beta compute os-config guest-policies lookup \
$GCE_INSTANCE_NAME \
--zone=$GCE_INSTANCE_ZONE
$=>
No effective guest policy found for [projects/$GCP_PROJECT_NAME/zones/$GCE_INSTANCE_ZONE/instances/$GCE_INSTANCE_NAME].
$GUEST_POLICY_NAME is not listed.
When the lookup command is used for another GCE instance ($GCE_ANOTHER_INSTANCE) with identical OS version, GCE metadata and GCE labels:
gcloud beta compute os-config guest-policies lookup \
$GCE_ANOTHER_INSTANCE \
--zone=$GCE_ANOTHER_ZONE
#=>
┌──────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ SOFTWARE RECIPES │
├───────────────────────────────────────────────────────────┬────────────────────┬─────────┬───────────────┤
│ SOURCE │ NAME │ VERSION │ DESIRED_STATE │
├───────────────────────────────────────────────────────────┼────────────────────┼─────────┼───────────────┤
│ projects/$GCP_PROJECT_ID/guestPolicies/. . . │ . . . │ . . . │ . . . │
│ projects/$GCP_PROJECT_ID/guestPolicies/$GUEST_POLICY_NAME │ $GUEST_POLICY_NAME │ 1.0 │ INSTALLED │
│ projects/$GCP_PROJECT_ID/guestPolicies/. . . │ . . . │ . . . │ . . . │
└───────────────────────────────────────────────────────────┴────────────────────┴─────────┴───────────────┘
$GUEST_POLICY_NAME is listed.
Why?
There could be a few reasons why
$GUEST_POLICY_NAMEisn't showing up in the response from thelookupcommand on$GCE_INSTANCE_NAME:latency: it may take some time for OSConfig to propagate
$GUEST_POLICY_NAMEwhen$GCE_INSTANCE_NAMEwas just createdwhile you might have enabled project-wide GCE metadata, as suggested here, it may help to add:
enable-guest-attributes:TRUEenable-osconfig:TRUEto
$GCE_INSTANCE_NAMEwith theadd-metadatacommand:if
$GUEST_POLICY_NAMEuses a Google Cloud Storage (GCS) Bucket to store packages or executables, check to see if the GCE default service account ($GCE_SERVICE_ACCOUNT) has at least one curated role with thestorage.objects.getpermission (e.g.,storage.objectViewer) with the GCS CLI (gsutil):if
$GCE_SERVICE_ACCOUNTdoes not have a role with thestorage.objects.getpermission, you can use thechcommand for theiamgroup to grant thestorage.objectViewercurated role:Make sure that Private Google Access is turned on for the subnet
$GCE_INSTANCE_NAMEis running in:Easily discover which subnet
$GCE_INSTANCE_NAMEis using with both the--flattenand--formatflags for thedescribecommand:Find out if
$GCE_INSTANCE_SUBNETWORKhas Google Private Access turned on:if the above is
False, then enable Private Google Access with the update subcommand for the samesubnetssubgroup:And if all of the above fail, make sure that
$GCE_INSTANCE_NAMEaligns with all of the criteria from$GUEST_POLICY_NAME: