Example 1

Install a package my-package that must be kept up to date on the following VM instances: my-instance-1 and my-instance-2.

assignment:
  instances:
  - zones/us-east1-c/instances/my-instance-1
  - zones/us-east1-c/instances/my-instance-2
packages:
- name: "my-package"
  desiredState: UPDATED

For more information about assigning guest policies for packages, see the Package JSON representation refrence document.

Example 2

Install the Cloud Monitoring agent, using the yum package manager, on all VM instances that have either of the following instance name prefix: test-instance- or dev-instance-.

assignment:
  instanceNamePrefixes:
  - "test-instance-"
  - "dev-instance-"
packages:
- name: "stackdriver-agent"
  desiredState: INSTALLED
  manager: YUM
packageRepositories:
- yum:
    id: google-cloud-monitoring
    displayName: "Google Cloud Monitoring Agent Repository"
    baseUrl: https://packages.cloud.google.com/yum/repos/google-cloud-monitoring-el7-x86_64
    gpgKeys:
    - https://packages.cloud.google.com/yum/doc/yum-key.gpg
    - https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg

For more information about assigning guest policies for pacakage repositories, see the PackageRepository JSON representation refrence document.

Example 3

Install my-package and remove bad-package-1 and bad-package-2 from instances with a specific set of labels. Also add repositories for the apt and yum package managers.

assignment:
  # Assign to VM instances where `(label.color=red AND label.env=test) OR (label.color=blue AND label.env=test)`
  groupLabels:
  - labels:
      color: red
      env: test
  - labels:
      color: blue
      env: test
packages:
- name: "my-package"
  desiredState: INSTALLED
- name: "bad-package-1"
  desiredState: REMOVED
- name: "bad-package-2"
  desiredState: REMOVED
  manager: APT  # Only apply this to systems with APT.
packageRepositories:
- apt:  # Only apply this to systems with APT.
    uri: "https://packages.cloud.google.com/apt"
    archiveType: DEB
    distribution: cloud-sdk-stretch
    components:
    - main
- yum:  # Only apply this to systems with YUM.
    id: google-cloud-sdk
    displayName: "Google Cloud SDK"
    baseUrl: https://packages.cloud.google.com/yum/repos/cloud-sdk-el7-x86_64
    gpgKeys:
    - https://packages.cloud.google.com/yum/doc/yum-key.gpg
    - https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg

Example 4

Installs software from an MSI hosted on Cloud Storage to all instances in us-east1-b and us-east1-d.

assignment:
  zones:
  - us-east1-b
  - us-east1-d
recipes:
- name: "swr-msi-gcs"
  desiredState: INSTALLED
  artifacts:
  - id: "the-msi"
    gcs:
      bucket: "my-bucket"
      object: "executable.msi"  # full URI gs://my-bucket/executable.msi#nnnnn
      generation: 1546030865175603
  installSteps:
  - msiInstallation:

For more information about configuring recipe policies, see the SoftwareRecipe JSON representation refrence document.

Example 5

Install software by running an inline script on all VM instances that meet the following requirements:

assignment:
  osTypes:
  - osShortName: rhel
    osVersion: "7"
  groupLabels:
  - labels:
      color: red
recipes:
- name: recipe-runscript
  desiredState: INSTALLED
  installSteps:
  - scriptRun:
      script: |-
        #!/bin/bash
        touch /TOUCH_FILE

For more information about configuring recipe policies, see the SoftwareRecipe JSON representation refrence document.