Deploying the Datadog Agent with Ansible - How to Use the Role
When you distribute the Datadog Agent with the role in the Ansible collection datadog.dd, what you decide comes down to four groups of role variables. This article uses only the official variable names to organize which files the variables land in, what changes when Linux and Windows are mixed, and how to run re-executions and updates.
What You Decide When Deploying with Ansible Comes Down to Four Groups of Role Variables
Datadog's official Ansible content is gathered in the Ansible Galaxy collection datadog.dd, and within it the role datadog.dd.agent handles installing and configuring the Datadog Agent (as of September 2026; source: Ansible (Agent)). Let us clear up one confusion first. The Ansible listed among the integrations is a callback plugin that sends playbook execution results (elapsed time and the number of failed tasks) to Datadog; it is not a tool for distributing the Agent (source: Ansible (Integration)). The comparison of the three installation routes is left to the Linux installation article; this article covers what comes after you have chosen Ansible. Although the role has many variables, the decisions fit into four groups, and the role absorbs OS differences, so writing the four groups in vars lets you distribute with a single playbook even in a mixed environment.
- 1. Key and site - datadog_api_key / datadog_site
- 2. Version - datadog_agent_version (pinned) / datadog_agent_major_version
- 3. Contents of datadog.yaml - datadog_config (tags / log enablement / APM, etc.)
- 4. Contents of conf.d - datadog_checks (conf.yaml per check) and datadog_integration
Installing the Collection and the Minimal Playbook
The prerequisite is Ansible v2.10 or later, and the targets are Debian / RHEL / SUSE family Linux, macOS, and Windows (as of September 2026; source: Ansible (Agent)). The installation commands are as shown in the table. The minimal playbook simply imports the role and passes the API key.
- hosts: servers
tasks:
- import_role:
name: datadog.dd.agent
vars:
datadog_api_key: "<YOUR_DD_API_KEY>"The API key is required from role 4.21 onward. If you inject the key externally, such as by baking it into an image, either pass a placeholder key and replace it later or turn off configuration management with datadog_manage_config: false (source: Ansible Standalone Role). For key handling, see the API Key entry.
| Command / notation | Purpose |
|---|---|
| ansible-galaxy collection install datadog.dd | Install from Galaxy |
| collections: - name: datadog.dd in requirements.yml | Install together with other collections (-r requirements.yml) |
| ansible-galaxy collection install datadog.dd --upgrade | Update the collection (it does not upgrade automatically) |
| ansible-galaxy collection install datadog.dd:==5.0.0 | Install a specific version (to roll back when something breaks) |
| Red Hat Automation Hub | Route to obtain the Red Hat certified version |
Which Files the Role Variables Land In
Hesitation over role variable design disappears once you know "which Agent file that variable gets written to." datadog_config is the very content of datadog.yaml, and the role writes it out to the correct location for each OS. In datadog_checks, the top-level key is the check name and the value is the content of conf.yaml, and on Agent v6 / v7 it lands in /etc/datadog-agent/conf.d/<check name>.d/conf.yaml (as of September 2026; source: Ansible Standalone Role). Configuration for your own custom checks can be distributed through this route as well. datadog_integration is not configuration but a variable that installs / removes integration packages themselves with a version (Agent v6.8 or later), used when you want to update just one integration without upgrading the whole Agent.
| Variable | Where it lands / how it takes effect | Notes |
|---|---|---|
| datadog_api_key | api_key in datadog.yaml | Required from 4.21 onward |
| datadog_site | site in datadog.yaml | Default datadoghq.com. EU is datadoghq.eu, US3 is us3.datadoghq.com |
| datadog_config | The whole of datadog.yaml (tags / log_level / logs_enabled / apm_config, etc.) | The role writes to the correct path per OS |
| datadog_checks | conf.d/<check name>.d/conf.yaml | Key = check name, value = content of conf.yaml |
| datadog_disable_untracked_checks | Removes checks not in datadog_checks or datadog_additional_checks | Set true to eliminate configuration drift |
| datadog_integration | install / remove of integration packages (with version) | Agent v6.8 or later. third_party: true for external integrations |
| datadog_agent_version | The Agent version to install (pinned) | Official docs recommend specifying it. Takes precedence over major_version |
| datadog_enabled | Whether the datadog-agent service starts | false installs only, without starting |
| datadog_apm_instrumentation_enabled | APM automatic instrumentation (host / docker / all) | Choose languages with datadog_apm_instrumentation_libraries |
How the Role Behaves When Operating Systems Are Mixed
The role installs the Agent by a different means for each OS. Linux uses the official apt / yum / zypper repositories, Windows uses the MSI, and macOS uses the DMG, with the source determined by datadog_agent_major_version (as of September 2026). The version, too, is converted to each OS's notation once you write datadog_agent_version: 7.16.0 a single time. Windows has two prerequisites: the ansible.windows collection and removing become: yes, and the officially recommended method is to attach ansible_become=no to the Windows group in the inventory (removing it on the playbook side makes Linux fail). The run account is passed via datadog_windows_ddagentuser_name and the matching password; for what it means, see the Windows installation article.
| OS | Source | Additional prerequisites | What 7.16.0 actually becomes |
|---|---|---|---|
| Debian / SUSE family | Official apt / zypper repositories | openSUSE / SLES need the community.general collection (not supported by Red Hat via Automation Hub) | 1:7.16.0-1 |
| RedHat family | Official yum repository | None | 7.16.0-1 |
| macOS | DMG (separate Intel / Apple Silicon builds from 7.70 onward) | datadog_macos_user must be an existing user | 7.16.0-1 |
| Windows | MSI | ansible.windows and ansible_become=no. Downgrade not supported | 7.16.0 |
Pin the Version, and Distribute Updates by Changing the Variable
The official docs recommend pinning the version (datadog_agent_version). Without pinning, every run installs the newest version of the specified major, and versions drift from host to host (as of September 2026; source: Ansible Standalone Role). Updating is simply rewriting the variable and re-running, and going from v6 to v7 takes only datadog_agent_major_version: 7 or a specific v7 version. The reverse direction is blocked by default and only goes down when you explicitly set datadog_agent_allow_downgrade: yes. Role v5 / collection v6 dropped support for Python 2, Agent 5, Ansible below 2.10, and older Amazon Linux 2 and CentOS, so check the generation of your target hosts before upgrading. The standard operating pattern is two stages: change only the version for the staging group first, then align the production group_vars to the same version.
Re-Runs and Distributing Configuration Changes - Dividing Work with Fleet Automation
Distributing configuration changes works the same way as installation: rewrite datadog_config or datadog_checks and re-run the playbook. Since the variables alone determine the outcome, managing the variables in Git puts you in a state where "which host has what" can be understood by reading the playbook. There is one caution: the role does not automatically delete the conf.yaml of a check you removed from datadog_checks. When you want to clean up, set datadog_disable_untracked_checks: true and list only what should remain in datadog_additional_checks (as of September 2026; source: Ansible Standalone Role). After distribution, divide roles with Fleet Automation, and not touching the same configuration from both sides prevents confusion.
| Situation | Ansible role | Fleet Automation |
|---|---|---|
| Initial distribution | Run the playbook | The UI shows installation steps per OS |
| Contents of datadog.yaml and conf.d | Distribute with datadog_config / datadog_checks | Verify configuration (keep rewrites on the Ansible side) |
| Tracking host count and versions | Inventory | List of Agents actually running |
| Remote updates | Enable the receiving end via datadog-installer with datadog_remote_updates | Execute remote upgrades |
Getting Stuck on the Key, Windows, and an Outdated Collection
The ways of getting stuck listed in the official troubleshooting almost all fall into three categories: "a variable that became required," "Windows prerequisites," and "an outdated collection or role" (as of September 2026; source: Ansible Standalone Role). They are summarized in the table.
| Symptom | Cause | Remedy |
|---|---|---|
| The role fails immediately | datadog_api_key is required from role 4.21 onward | Pass the key. For image baking, use a placeholder key or datadog_manage_config: false |
| Only Windows hosts fail | become: yes does not work on Windows | Add ansible_become=no to the Windows group in the inventory |
| A specific version will not install on Windows | 6.14.0 / 6.14.1 have an uninstaller defect that blocks installation | Specify 6.14.2 or later |
| service_facts breaks on Ubuntu 20.04 | A defect on the Ansible side | Update to Ansible v2.9.8 or later |
| A new variable has no effect | Collections installed from Galaxy are not updated automatically | ansible-galaxy collection install datadog.dd --upgrade |
| Fails on old CentOS / RHEL | Role v5 dropped support for CentOS 6 / 7 | Reconsider the target OS or stay on the v4 series of the role |
The first and fifth rows of the table are the typical cases where a playbook that used to work fails "even though nothing was changed." If you pin the role and collection versions just as you do the Agent, the cause of a failure is limited to your own changes, and isolating it becomes quicker.