Installer l'Agent Ops lors de la création de la VM
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Ce document explique comment la console Google Cloud peut installer automatiquement l'Agent Ops lorsque vous créez une instance de VM. Au cours du processus d'installation, le VM Manager de Compute Engine crée une règle d'OS de l'Agent Ops qui installe l'agent et le réinstalle si nécessaire. VM Manager vous aide à exécuter l'Agent Ops sur votre VM et garantit qu'il est toujours installé.
Présentation
VM Manager utilise les règles d'OS pour gérer l'installation de l'Agent Ops. Une règle de configuration est appliquée à une VM à l'aide d'un mappage appelé ID d'attribution, qui ressemble à l'exemple suivant :
goog-ops-agent-v2-x86-template-1-0-0-ZONE
Un ID d'attribution pour une règle d'OS de l'Agent Ops comprend les composants suivants :
Nom de la règle : "goog-ops-agent"
Modèle permettant de créer la règle : "v2-x86-template"
Une chaîne de version pour le modèle. La version, qui peut changer au fil du temps, est une valeur telle que "1-0-0".
Zone à laquelle l'ID d'attribution s'applique, dont la valeur est "us-central1-a"
Une VM est associée à un ID d'attribution à l'aide des étiquettes de l'instance de VM.
Une VM Compute Engine est une ressource surveillée de type gce_instance et inclut une étiquette zone. Lorsque vous utilisez la console Google Cloud pour créer une VM avec l'Agent Ops installé, VM Manager ajoute une autre étiquette à la VM, semblable à goog-ops-agent-policy:v2-x86-template-1-0-0. Cette étiquette identifie la stratégie, le modèle et la version :
Clé d'étiquette, identifiant de la règle : goog-ops-agent-policy
Valeur de l'étiquette, modèle de stratégie et version : v2-x86-template-1-0-0
Lorsque vous créez une VM dans la console Google Cloud , vous pouvez cocher la case Installer l'Agent Ops pour Monitoring et Logging. Lorsque vous cliquez sur Créer, VM Manager attribue à la VM l'étiquette goog-ops-agent-policy:v2-x86-template-1-0-0 et installe l'Agent Ops. Si la VM est la première VM de sa zone, VM Manager crée également une règle d'OS et une attribution de règle d'OS de l'Agent Ops pour cette zone.
Alors qu'une zone dispose d'une attribution de règle d'OS de l'Agent Ops, la règle d'OS de l'Agent Ops surveille les VM présentant les caractéristiques suivantes :
La VM possède le libellé goog-ops-agent-policy:v2-x86-template-1-0-0.
La VM se trouve dans la même zone que l'attribution de la règle d'OS de l'Agent Ops.
La règle d'OS de l'Agent Ops vérifie toutes les heures si l'Agent Ops est installé pour toutes les VM couvertes. Si l'Agent Ops n'est pas installé, la règle d'OS de l'Agent Ops installe la dernière version de l'agent.
Créer une VM avec une installation automatique de l'Agent Ops
Pour installer automatiquement l'Agent Ops lors de la création de la VM et appliquer l'attribution de la règle d'OS de l'Agent Ops à la VM, procédez comme suit :
Grant roles to your user account. Run the following command once for each of the following
IAM roles:
roles/osconfig.osPolicyAssignmentEditor
Lorsque vous installez automatiquement l'Agent Ops pour la première fois dans une zone, si vous n'avez pas activé VM Manager pour votre projet Google Cloud , le processus de création de la VM effectue les opérations suivantes :
Il permet à VM Manager de fonctionner en mode restreint.
Il crée la règle d'OS de l'Agent Ops et une attribution de règle d'OS de l'Agent Ops pour la zone. La stratégie d'OS de l'Agent Ops est un champ de l'attribution de stratégie.
Il active Patch, les règles d'OS et OS Inventory Management en définissant l'étiquette de métadonnées de la VM enable-osconfig sur TRUE.
Il crée la VM et lui attribue l'étiquette de règle d'OS de l'Agent Ops.
Si vous créez une VM et installez automatiquement l'Agent Ops dans une zone où une attribution de règle d'OS de l'Agent Ops existe déjà, le processus de création de la VM crée la VM et lui attribue l'étiquette de règle d'OS de l'Agent Ops.
Exemple
Votre projet Google Cloud ne comporte aucune attribution de règles d'OS de l'Agent Ops. Vous créez deux VM, instance-1 et instance-2 dans la zone us-central1-a. Vous créez ensuite instance-3 et instance-4 dans la zone us-east1-b. instance-1, instance-2 et instance-3 avaient la case Installer l'Agent Ops pour Monitoring et Logging cochée lors de la création.
Lorsque vous créez instance-1, VM Manager crée une règle d'OS de l'Agent Ops pour la zone us-central1-a et une attribution de règle d'OS avec l'ID goog-ops-agent-v2-x86-template-1-0-0-us-central1-a.
VM Manager définit ensuite l'étiquette de la règle sur instance-1.
Lorsque vous créez instance-2, VM Manager définit la même étiquette de règle sur instance-2.
Lorsque vous créez instance-3, VM Manager crée une règle d'OS de l'Agent Ops pour la zone us-east1-b et une attribution de règle d'OS avec l'ID goog-ops-agent-v2-x86-template-1-0-0-us-east1-b. VM Manager attribue ensuite l'étiquette de règle à instance-3.
Les règles d'OS de l'Agent Ops couvrent ensuite les VM suivantes en fonction des ID d'attribution de règle d'OS de l'Agent Ops :
Par défaut, instance-4 n'est pas couverte, car vous n'avez pas sélectionné Installer l'Agent Ops pour Monitoring et Logging. Elle n'a donc pas l'étiquette goog-ops-agent-policy:v2-x86-template-1-0-0. Si vous souhaitez également appliquer la règle d'OS de l'Agent Ops à l'instance-4, consultez la section Ajouter la couverture de la règle d'OS de l'Agent Ops à une VM existante.
Gérer les versions de l'Agent Ops sur les VM couvertes par la règle d'OS de l'Agent Ops
La règle d'OS de l'Agent Ops ne met pas à jour l'Agent Ops lorsque de nouvelles versions de l'agent sont publiées. Tant que la version de l'Agent Ops est installée sur la VM, la règle n'a aucun effet. Si vous désinstallez l'Agent Ops, la règle détecte que l'Agent Ops n'est pas installé, puis installe la dernière version.
Pour mettre à niveau votre VM vers la dernière version de l'Agent Ops, désinstallez la version que vous exécutez actuellement et laissez la règle d'OS de l'Agent Ops installer la dernière version.
Les règles d'OS sont des outils génériques pour l'installation de packages. Par défaut, lorsque VM Manager est activé, car vous avez créé une VM avec l'Agent Ops installé automatiquement, VM Manager est activé en mode limité.
Pour en savoir plus sur les modes et les tarifs de VM Manager, consultez Tarifs de VM Manager.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/04 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/04 (UTC)."],[],[],null,["# Install the Ops Agent during VM creation\n\nThis document describes how the Google Cloud console can automatically install the\nOps Agent for you when you create a VM instance. During the installation\nprocess, the Compute Engine [VM Manager](/compute/docs/vm-manager) creates an\nOps Agent OS policy\nthat installs the agent and reinstalls it when necessary. The\nVM Manager helps you get the Ops Agent running on your VM and ensures\nthat the agent is always installed.\n\nOverview\n--------\n\nThe VM Manager uses OS policies to manage the Ops Agent\ninstallation. A configuration policy is applied to a VM by using a mapping\ncalled an *assignment ID*, which looks like the following example: \n\n```\ngoog-ops-agent-v2-x86-template-1-0-0-ZONE\n```\n\nAn assignment ID for an Ops Agent OS policy consists of the following\ncomponents:\n\n- The name of the policy: \"goog-ops-agent\"\n- A template for creating the policy: \"v2-x86-template\"\n- A version string for the template. The version, which might change over time, is a value like \"\u003cvar translate=\"no\"\u003e1-0-0\u003c/var\u003e\".\n- The zone to which the assignment ID applies, a value like \"us-central1-a\".\n\nA VM is associated with an assignment ID by using the labels on the VM instance.\nA Compute Engine VM is a monitored resource of type\n[`gce_instance`](/monitoring/api/resources#tag_gce_instance)\nand includes a `zone` label. When you use the Google Cloud console to\ncreate a VM with the Ops Agent installed, the VM Manager adds another\nlabel to the VM, which looks like `goog-ops-agent-policy:v2-x86-template-`\u003cvar translate=\"no\"\u003e1-0-0\u003c/var\u003e. This label identifies the\npolicy, template, and version:\n\n- Label key, the identifier for the policy: `goog-ops-agent-policy`\n- Label value, the policy template and version: `v2-x86-template-`\u003cvar translate=\"no\"\u003e1-0-0\u003c/var\u003e\n\nWhen you create a VM in the Google Cloud console, you can select the\n**Install Ops Agent for Monitoring and Logging** checkbox. When you click\n**Create** , VM Manager assigns the VM a label of `goog-ops-agent-policy:v2-x86-template-`\u003cvar translate=\"no\"\u003e1-0-0\u003c/var\u003e and\ninstalls the Ops Agent. If the VM is the first VM in its zone, then\nVM Manager also creates an Ops Agent OS policy and an Ops Agent OS\npolicy assignment for that zone.\n\nWhile a zone has an Ops Agent OS policy assignment, the Ops Agent OS policy\nmonitors VMs that have the following characteristics:\n\n- The VM has the `goog-ops-agent-policy:v2-x86-template-`\u003cvar translate=\"no\"\u003e1-0-0\u003c/var\u003e label.\n- The VM is in the same zone as the Ops Agent OS policy assignment.\n\nThe Ops Agent OS policy checks every hour whether its\ncovered VMs have the Ops Agent installed. If the Ops Agent isn't\ninstalled, then the Ops Agent OS policy installs the latest version\nof the agent.\n\nCreate a VM with automatic installation of the Ops Agent\n--------------------------------------------------------\n\nTo install the Ops Agent automatically during VM creation and apply the\nOps Agent OS policy assignment to the VM, do the following:\n\n1.\n Grant roles to your user account. Run the following command once for each of the following\n IAM roles:\n `roles/osconfig.osPolicyAssignmentEditor`\n\n ```bash\n gcloud projects add-iam-policy-binding PROJECT_ID --member=\"user:\u003cvar translate=\"no\"\u003eUSER_IDENTIFIER\u003c/var\u003e\" --role=ROLE\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: your project ID.\n - \u003cvar translate=\"no\"\u003eUSER_IDENTIFIER\u003c/var\u003e: the identifier for your user account---for example, `myemail@example.com`.\n - \u003cvar translate=\"no\"\u003eROLE\u003c/var\u003e: the IAM role that you grant to your user account.\n2. Follow the steps in [Create a VM instance from a public image](/compute/docs/instances/create-start-instance#publicimage). Before you click **Create** , select the **Install Ops Agent for Monitoring and Logging** checkbox:\n\n | **Note:** When you select the **Install Ops Agent for Monitoring and Logging** checkbox during VM creation, the examples on the tabs in the **Equivalent code** flyout are updated to include the steps for creating the Ops Agent OS policy. There is no REST equivalent for creating an Ops Agent OS policy.\n3. Click **Create** .\n\n When you install the Ops Agent automatically for the first time in a zone,\n if you don't have VM Manager enabled for your Google Cloud project,\n then the VM-creation process does the following:\n 1. Enables VM Manager to operate in [restricted mode](/compute/docs/vm-manager#pricing).\n 2. Creates the Ops Agent OS policy and an Ops Agent OS policy assignment for the zone. The Ops Agent OS policy is a field of the policy assignment.\n 3. Enables Patch, OS policies, and OS inventory management by setting the VM metadata label `enable-osconfig` to `TRUE`.\n 4. Creates the VM and assigns it the Ops Agent OS policy label.\n\n \u003cbr /\u003e\n\n If you create a VM and automatically install the Ops Agent in a zone\n where an Ops Agent OS policy assignment already exists, then the VM-creation\n process creates the VM and assigns it the Ops Agent OS policy label.\n\n \u003cbr /\u003e\n\n \u003cbr /\u003e\n\n\u003cbr /\u003e\n\nExample\n-------\n\nYour Google Cloud project doesn't have any Ops Agent OS\npolicy assignments. You create two VMs, *instance-1* and *instance-2* in the\n`us-central1-a` zone. You\nthen create *instance-3* and *instance-4* in the `us-east1-b` zone. *instance-1* , *instance-2* , and\n*instance-3* had the **Install Ops Agent for Monitoring and Logging** checkbox\nselected during creation.\n\n- When you create *instance-1* , VM Manager creates an Ops Agent OS policy for the `us-central1-a` zone and an OS policy assignment with the ID `goog-ops-agent-v2-x86-template-`\u003cvar translate=\"no\"\u003e1-0-0\u003c/var\u003e`-us-central1-a`. VM Manager then sets the policy label on *instance-1*.\n- When you create *instance-2* , VM Manager sets the same policy label on *instance-2*.\n- When you create *instance-3* , VM Manager creates an Ops Agent OS policy for the `us-east1-b` zone and an OS policy assignment with the ID `goog-ops-agent-v2-x86-template-`\u003cvar translate=\"no\"\u003e1-0-0\u003c/var\u003e`-us-east1-b`. VM Manager then assigns the policy label to *instance-3*.\n\nThe Ops Agent OS policies then cover the following VMs based on the\nOps Agent OS policy assignment IDs:\n\nBy default, *instance-4* isn't covered because you didn't select\n**Install Ops Agent for Monitoring and Logging** , so it doesn't have the\n`goog-ops-agent-policy:v2-x86-template-`\u003cvar translate=\"no\"\u003e1-0-0\u003c/var\u003e label. If you also want to apply the Ops Agent OS policy to\n*instance-4* , then see\n[Add Ops Agent OS policy coverage to an existing VM](/stackdriver/docs/solutions/agents/ops-agent/manage-policies-auto-install#add-coverage).\n\nManage Ops Agent versions on VMs covered by the Ops Agent OS policy\n-------------------------------------------------------------------\n\nThe Ops Agent OS policy doesn't update the Ops Agent when new versions of the\nagent are released. As long as the VM has some version of the Ops Agent\ninstalled, the policy does nothing. If you uninstall the Ops Agent, then the\npolicy detects that the Ops Agent isn't installed and then installs the latest\nversion.\n\nTo upgrade your VM to the latest version of the Ops Agent, uninstall the\nversion that you are currently running and let the Ops Agent OS policy\ninstall the latest version.\n\nIf you need to install a previous version of the Ops Agent, you can\n[uninstall the Ops Agent on VMs covered by the Ops Agent OS policy](/stackdriver/docs/solutions/agents/ops-agent/manage-policies-auto-install#uninstall)\nand then [install a specific version of the agent](/stackdriver/docs/solutions/agents/ops-agent/installation#install-specific-version).\n\nTroubleshooting\n---------------\n\nFor information about troubleshooting agent installation and Ops Agent OS\npolicies, see [Manage VMs covered by the Ops Agent OS policy](/stackdriver/docs/solutions/agents/ops-agent/manage-policies-auto-install)\nand\n[Agent diagnostics tool for automatic installation policies](/stackdriver/docs/solutions/agents/ops-agent/troubleshoot-find-info#agent_diagnostics_tool_for_automatic_installation_policies).\n\nPricing\n-------\n\nOS policies are generic tools for installing packages. By default, when\nVM Manager is enabled because you've created a VM with the Ops Agent\nautomatically installed, VM Manager is enabled in the limited mode.\nFor information about VM Manager modes and pricing, see\n[VM Manager Pricing](/compute/docs/vm-manager#pricing).\n\nWhat's next\n-----------\n\nFor information about managing VMs covered by the Ops Agent OS policy, see\n[Manage VMs covered by the Ops Agent OS policy](/stackdriver/docs/solutions/agents/ops-agent/manage-policies-auto-install)."]]