### Example: Install and Remove Integrations Source: https://github.com/ansible-collections/datadog/blob/main/roles/agent/README.md This example demonstrates installing version 1.11.0 of the ElasticSearch integration and removing the postgres integration. ```yaml datadog_integration: datadog-elastic: action: install version: 1.11.0 datadog-postgres: action: remove ``` -------------------------------- ### Datadog Integration Management Example Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/01-role-agent-reference.md An example demonstrating how to install a specific version of the 'datadog-elastic' integration and remove the 'datadog-postgres' integration. This syntax is available for Agent v6.8+. ```yaml datadog_integration: datadog-elastic: action: install version: 1.11.0 datadog-postgres: action: remove ``` -------------------------------- ### Full-Featured Datadog Agent Installation (EU Site) Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/02-configuration.md This playbook demonstrates a comprehensive Datadog Agent setup for the EU Datadog site, enabling logging, tracing, and network performance monitoring. It includes version pinning and custom tags. ```yaml - hosts: datadog_agents become: yes roles: - datadog.dd.agent vars: datadog_api_key: "{{ vault_datadog_api_key }}" datadog_site: datadoghq.eu datadog_agent_version: "7.50.0" datadog_config: log_level: INFO tags: - env:production - version:7.50.0 apm_config: enabled: true logs_enabled: true network_config: enabled: true datadog_checks: process: init_config: instances: - name: web search_string: [nginx] postgres: init_config: instances: - host: localhost port: 5432 ``` -------------------------------- ### Install Ansible Windows Collection Source: https://github.com/ansible-collections/datadog/blob/main/README.md Install the `ansible.windows` collection if you need to manage Windows hosts. ```shell ansible-galaxy collection install ansible.windows ``` -------------------------------- ### Install Community General Collection for SUSE Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/08-troubleshooting-reference.md For SUSE hosts, ensure the `community.general` collection is installed if you encounter errors resolving modules or actions. ```bash ansible-galaxy collection install community.general ``` -------------------------------- ### Install Third-Party Integration Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/04-playbook-patterns.md Installs community or Marketplace integrations. Set `third_party: true` to indicate a non-core integration. ```yaml --- - hosts: all become: yes roles: - datadog.dd.agent vars: datadog_api_key: "YOUR_API_KEY" datadog_integration: community-custom-check: action: install version: 1.0.0 third_party: true ``` -------------------------------- ### Windows MSI Installation Arguments Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/06-platform-specifics.md Defines the arguments used for installing the Datadog Agent on Windows via MSI. Common options include specifying features to install or the installation directory. ```yaml win_install_args: " " ``` -------------------------------- ### Install Ansible Community General Collection Source: https://github.com/ansible-collections/datadog/blob/main/README.md Install the `community.general` collection when managing openSUSE/SLES hosts. ```shell ansible-galaxy collection install community.general ``` -------------------------------- ### Example YAML Before FQCN Formatting Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/03-task-system.md Illustrates the input format of a YAML task before the `format_fqcn` task is applied. ```yaml --- - name: Install datadog agent datadog.dd.agent: api_key: "{{ datadog_api_key }}" ``` -------------------------------- ### Install invoke Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/03-task-system.md Install the 'invoke' package to resolve 'command not found' errors. This is a prerequisite for running custom tasks. ```bash # Install invoke pip install invoke ``` -------------------------------- ### Start Datadog System Probe Source: https://github.com/ansible-collections/datadog/blob/main/roles/agent/README.md Use these commands to start the Datadog system probe service on Linux systems, especially for older Agent versions. ```bash sudo service datadog-agent-sysprobe start ``` ```bash sudo initctl start datadog-agent-sysprobe ``` ```bash sudo service datadog-agent restart ``` ```bash sudo service enable datadog-agent-sysprobe ``` -------------------------------- ### Minimal Agent Installation Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/04-playbook-patterns.md Installs the latest Agent v7, configures for the US site, enables the agent service, and creates the dd-agent user/group. No additional checks are applied. ```yaml --- - hosts: all become: yes roles: - datadog.dd.agent vars: datadog_api_key: "YOUR_API_KEY" ``` -------------------------------- ### Control Windows Agent Installation Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/02-configuration.md Use `datadog_windows_skip_install` to prevent installation even if the Agent is not detected. Use `datadog_windows_force_reinstall` to ensure a reinstallation occurs, overriding the skip flag. ```yaml datadog_windows_skip_install: false ``` ```yaml datadog_windows_force_reinstall: false ``` -------------------------------- ### Run FQCN Formatting Command Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/03-task-system.md Execute the FQCN formatting task from the collection root or after installing invoke. ```bash # From collection root python -m invoke format_fqcn ``` ```bash # Or install invoke and use directly invoke format_fqcn ``` -------------------------------- ### Install Specific Integrations Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/04-playbook-patterns.md Installs specific integration versions on Agent v6.8+. Use this to manage exact versions of integrations. ```yaml --- - hosts: all become: yes roles: - datadog.dd.agent vars: datadog_api_key: "YOUR_API_KEY" datadog_integration: datadog-elasticsearch: action: install version: 1.20.0 datadog-mysql: action: install version: 3.0.0 datadog-kafka: action: install version: 2.5.0 ``` -------------------------------- ### Datadog Agent API Key Handling Source: https://github.com/ansible-collections/datadog/blob/main/roles/agent/README.md Starting from role version `4.21`, the API key is mandatory. To install without specifying a key, use a dummy key and replace it later, or disable managed configuration. ```yaml datadog_manage_config: false ``` -------------------------------- ### Agent v6 Installation Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/04-playbook-patterns.md Use this playbook to pin the Datadog Agent installation to version 6 instead of the default v7. ```yaml --- - hosts: all become: yes roles: - datadog.dd.agent vars: datadog_api_key: "YOUR_API_KEY" datadog_agent_major_version: 6 ``` -------------------------------- ### Install Third-Party Datadog Integration Source: https://github.com/ansible-collections/datadog/blob/main/roles/agent/README.md To install third-party integrations from the Datadog community or Marketplace, set `third_party: true` in addition to the action and version. ```yaml datadog_integration: : action: version: third_party: true ``` -------------------------------- ### Install Latest Agent v6 Source: https://github.com/ansible-collections/datadog/blob/main/roles/agent/README.md Installs the latest Datadog Agent version 6. Ensure the `datadog_api_key` is set. ```yaml - hosts: servers roles: - { role: datadog.datadog, become: yes } vars: datadog_agent_major_version: 6 datadog_api_key: "" ``` -------------------------------- ### Install dirmngr for Debian Stretch Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/08-troubleshooting-reference.md This task ensures the 'dirmngr' package is installed, which is required by the 'apt_key' module on Debian 9. ```yaml pre_tasks: - name: Install dirmngr for Debian Stretch apt: name: dirmngr state: present when: ansible_facts.distribution == "Debian" and ansible_facts.distribution_version == "9" ``` -------------------------------- ### Minimal Datadog Agent Installation (US Site) Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/02-configuration.md Use this playbook for a basic Datadog Agent installation on the US Datadog site. It requires the Datadog API key to be stored in Ansible Vault. ```yaml - hosts: datadog_agents become: yes roles: - datadog.dd.agent vars: datadog_api_key: "{{ vault_datadog_api_key }}" ``` -------------------------------- ### Get OS Version Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/08-troubleshooting-reference.md Use this command to retrieve the operating system and kernel version information. ```bash uname -a ``` -------------------------------- ### Configure Advanced Installer Settings Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/02-configuration.md These advanced variables are for special scenarios only, allowing configuration of the datadog-installer and APM injection details. ```yaml datadog_installer_registry: "" datadog_installer_auth: "" datadog_installer_version: "" datadog_apm_inject_version: "" ``` -------------------------------- ### Windows Installation Configuration Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/04-playbook-patterns.md Deploy the Datadog Agent on Windows servers. This configuration specifies the agent user credentials and custom tags for the Datadog configuration. Note that `become: yes` is not required for Windows. ```yaml --- - hosts: windows_servers roles: - datadog.dd.agent vars: datadog_api_key: "YOUR_API_KEY" datadog_windows_ddagentuser_name: "DOMAIN\DatadogAgent" datadog_windows_ddagentuser_password: "{{ vault_windows_password }}" datadog_config: tags: - "windows:true" - "env:production" ``` -------------------------------- ### Install Datadog Integration Source: https://github.com/ansible-collections/datadog/blob/main/roles/agent/README.md Use this resource to install a specific version of a Datadog integration. This is useful for upgrading integrations independently of the Agent. Ensure the Agent version is 6.8+. ```yaml datadog_integration: : action: version: ``` -------------------------------- ### Example YAML After FQCN Formatting Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/03-task-system.md Shows the output format of a YAML task after the `format_fqcn` task has corrected FQCN violations. ```yaml --- - name: Install datadog agent import_role: name: datadog.dd.agent ``` -------------------------------- ### Check Datadog Agent Installation Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/08-troubleshooting-reference.md Verify if the Datadog agent package is installed on the target system using package manager commands for Linux or PowerShell for Windows. ```bash # Linux dpkg -l | grep datadog-agent rpm -qa | grep datadog-agent # Windows Get-Package | grep -i datadog ``` -------------------------------- ### Datadog Agent Example Configuration Source: https://github.com/ansible-collections/datadog/blob/main/roles/agent/README.md This configuration enables process collection, customizes sensitive words, and configures system probe, network, service monitoring, and runtime security. ```yaml datadog_config: process_config: enabled: "true" # type: string scrub_args: true custom_sensitive_words: ['consul_token','dd_api_key'] system_probe_config: sysprobe_socket: /opt/datadog-agent/run/sysprobe.sock network_config: enabled: true service_monitoring_config: enabled: true runtime_security_config: enabled: true system_probe_other_config: traceroute: enabled: true ``` -------------------------------- ### Verify OS Support with Ansible Setup Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/08-troubleshooting-reference.md Check if your operating system is supported by the Datadog Ansible collection. This command filters facts to show the OS family. ```bash ansible localhost -m ansible.builtin.setup -a "filter=ansible_os_family" ``` -------------------------------- ### Linux Version String Translation Example Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/06-platform-specifics.md Illustrates how the Datadog Agent role translates a common version string into OS-specific formats for Debian/Ubuntu, RedHat/CentOS, and SLES/openSUSE. ```yaml # Input datadog_agent_version: "7.50.0" # Output by platform Debian/Ubuntu: 1:7.50.0-1 (epoch:version-release) RedHat/CentOS: 7.50.0-1 (version-release) SLES/openSUSE: 1:7.50.0-1 (epoch:version-release) ``` -------------------------------- ### Install Datadog Agent with elevated privileges Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/08-troubleshooting-reference.md This task demonstrates how to include the Datadog Agent role and ensure it runs with administrator privileges using 'become'. ```yaml tasks: - name: Install Agent include_role: name: datadog.dd.agent become: yes become_method: runas ``` -------------------------------- ### Install Datadog Ansible Role Source: https://github.com/ansible-collections/datadog/blob/main/roles/agent/README.md Installs the standalone Datadog role from Ansible Galaxy. This is a prerequisite before using the role in a playbook. ```shell ansible-galaxy install datadog.datadog ``` -------------------------------- ### Install ansible-lint Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/03-task-system.md Install the 'ansible-lint' package to resolve 'ansible-lint Not Found' errors. This tool is used for linting Ansible roles. ```bash # Install ansible-lint pip install ansible-lint ``` -------------------------------- ### Install Datadog Ansible Collection Source: https://github.com/ansible-collections/datadog/blob/main/README.md Install the `datadog.dd` collection using Ansible Galaxy. This is the primary method for obtaining the collection. ```shell ansible-galaxy collection install datadog.dd ``` -------------------------------- ### Windows Host Inventory Configuration Source: https://github.com/ansible-collections/datadog/blob/main/roles/agent/README.md Example inventory file configuration for Windows hosts, setting `ansible_become` to `no` at the group level to prevent the role from failing. ```ini [servers] linux1 ansible_host=127.0.0.1 linux2 ansible_host=127.0.0.2 windows1 ansible_host=127.0.0.3 ansible_become=no windows2 ansible_host=127.0.0.4 ansible_become=no ``` ```ini [linux] linux1 ansible_host=127.0.0.1 linux2 ansible_host=127.0.0.2 [windows] windows1 ansible_host=127.0.0.3 windows2 ansible_host=127.0.0.4 [windows:vars] ansible_become=no ``` -------------------------------- ### Ansible Task with Correct FQCN (Good) Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/03-task-system.md Example of an Ansible task correctly using the Fully Qualified Collection Name (FQCN) prefix. ```yaml # Good - name: Task ansible.builtin.command: echo hello ``` -------------------------------- ### Datadog Agent Installation on Windows Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/02-configuration.md This playbook is designed for installing the Datadog Agent on Windows systems. It requires specifying the domain user and password for the agent service, stored in Ansible Vault. ```yaml - hosts: windows_agents roles: - datadog.dd.agent vars: datadog_api_key: "{{ vault_datadog_api_key }}" datadog_windows_ddagentuser_name: "DOMAIN\DatadogAgent" datadog_windows_ddagentuser_password: "{{ vault_windows_password }}" ``` -------------------------------- ### Override Windows Installation Paths Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/02-configuration.md Customize the installation directory for the Datadog Agent program files and configuration files on Windows. Defaults to standard Windows locations. ```yaml datadog_windows_program_files_dir: "" datadog_windows_config_files_dir: "" ``` -------------------------------- ### Run ansible-lint in CI/CD Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/03-task-system.md Integrate ansible-lint checks into your CI/CD workflow to ensure code quality. This example runs ansible-lint on all roles. ```yaml - name: Run ansible-lint run: ansible-lint roles/ ``` -------------------------------- ### Specify APM Instrumentation Libraries Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/02-configuration.md List the specific libraries for which to install APM instrumentation. If not specified, a default set of common libraries is used. ```yaml datadog_apm_instrumentation_libraries: - java - python - dotnet - js - ruby ``` -------------------------------- ### Ansible Task with Corrected FQCN (Good) Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/03-task-system.md Example of an Ansible task using the current, correct Fully Qualified Collection Name (FQCN) format. ```yaml # Good - import_role: name: datadog.dd.agent ``` -------------------------------- ### Tagging Playbook for Selective Execution Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/04-playbook-patterns.md Use tags to control which parts of a playbook are executed. This example tags the entire playbook with 'datadog' and 'monitoring'. ```yaml --- - hosts: all become: yes roles: - datadog.dd.agent tags: - datadog - monitoring vars: datadog_api_key: "{{ vault_datadog_api_key }}" datadog_checks: nginx: init_config: instances: - nginx_status_url: http://localhost/nginx_status/ ``` -------------------------------- ### Enable Datadog Agent Service Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/02-configuration.md Set `datadog_enabled` to true to ensure the Datadog Agent service is enabled and started. ```yaml datadog_enabled: true ``` -------------------------------- ### Ansible Collection Plugins Directory Structure Source: https://github.com/ansible-collections/datadog/blob/main/plugins/README.md This example shows the typical directory layout for organizing different types of Ansible plugins within a collection. Each subdirectory corresponds to a specific plugin type. ```directory └── plugins ├── action ├── become ├── cache ├── callback ├── cliconf ├── connection ├── filter ├── httpapi ├── inventory ├── lookup ├── module_utils ├── modules ├── netconf ├── shell ├── strategy ├── terminal ├── test └── vars ``` -------------------------------- ### Pinned Agent Version Installation Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/04-playbook-patterns.md Ensures all hosts receive a specific Agent version (e.g., 7.50.0) regardless of OS. The playbook automatically translates OS-specific version strings. ```yaml --- - hosts: all become: yes roles: - datadog.dd.agent vars: datadog_api_key: "YOUR_API_KEY" datadog_agent_version: "7.50.0" ``` -------------------------------- ### Select Datadog Agent Flavor Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/02-configuration.md Choose the package flavor or variant for specialized Datadog Agent installations, such as the 'datadog-iot-agent' for Raspberry Pi. The default is 'datadog-agent'. ```yaml datadog_agent_flavor: "datadog-agent" ``` -------------------------------- ### Install Specific Datadog Ansible Collection Version Source: https://github.com/ansible-collections/datadog/blob/main/README.md Install a specific version of the `datadog.dd` collection, for example, version 5.0.0, using the `==` operator. ```shell ansible-galaxy collection install datadog.dd:==5.0.0 ``` -------------------------------- ### Datadog Agent Configuration Playbook Source: https://github.com/ansible-collections/datadog/blob/main/roles/agent/README.md Configure the Datadog Agent with API key, version, tags, log level, APM, logs, and specific checks like process, ssh_check, and nginx. Also includes integration setup for elastic and postgres. ```yaml - hosts: servers roles: - { role: datadog.datadog, become: yes } vars: datadog_api_key: "" datadog_agent_version: "7.16.0" datadog_config: tags: - ":" - ":" log_level: INFO apm_config: enabled: true logs_enabled: true # available with Agent v6 and v7 datadog_checks: process: init_config: instances: - name: ssh search_string: ['ssh', 'sshd' ] - name: syslog search_string: ['rsyslog' ] cpu_check_interval: 0.2 exact_match: true ignore_denied_access: true ssh_check: init_config: instances: - host: localhost port: 22 username: root password: sftp_check: True private_key_file: add_missing_keys: True nginx: init_config: instances: - nginx_status_url: http://example.com/nginx_status/ tags: - "source:nginx" - "instance:foo" - nginx_status_url: http://example2.com:1234/nginx_status/ tags: - "source:nginx" - ":" #Log collection is available on Agent 6 and 7 logs: - type: file path: /var/log/access.log service: myapp source: nginx sourcecategory: http_web_access - type: file path: /var/log/error.log service: nginx source: nginx sourcecategory: http_web_access # datadog_integration is available on Agent 6.8+ datadog_integration: datadog-elastic: action: install version: 1.11.0 datadog-postgres: action: remove network_config: enabled: true ``` -------------------------------- ### Get Ansible Version Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/08-troubleshooting-reference.md Use this command to retrieve the currently installed Ansible version for diagnostic purposes. ```bash ansible --version ``` -------------------------------- ### Initialize Invoke Namespace Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/03-task-system.md Sets up the main invoke namespace, configures UTF-8 encoding for command output, and adds the 'role' collection. ```python from invoke import Collection from . import role ns = Collection() ns.add_collection(role) ns.configure({ "run": { "encoding": "utf-8" } }) ``` -------------------------------- ### Check disk space for /var Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/08-troubleshooting-reference.md Verify available disk space on the /var partition, as insufficient space can cause apt operations to fail. ```bash df -h /var ``` -------------------------------- ### Mixed Linux/Windows Inventory Handling Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/04-playbook-patterns.md Manage both Windows and Linux servers within a single Ansible playbook. This example demonstrates applying OS-specific configurations using `set_fact` based on `ansible_facts.os_family`. ```yaml --- - hosts: all roles: - datadog.dd.agent vars: datadog_api_key: "YOUR_API_KEY" datadog_agent_version: "7.50.0" tasks: - name: Apply Windows-specific config set_fact: datadog_windows_ddagentuser_name: "DOMAIN\DatadogAgent" when: ansible_facts.os_family == "Windows" - name: Apply Linux-specific config set_fact: datadog_additional_groups: "docker,wheel" when: ansible_facts.os_family in ["Debian", "RedHat", "Suse"] ``` -------------------------------- ### Importing the datadog.dd.agent Role with Become Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/01-role-agent-reference.md Illustrates importing the datadog.dd.agent role and enabling privilege escalation using 'become'. Note that 'become' is not required on Windows. ```yaml - import_role: name: datadog.dd.agent become: yes # Not required on Windows ``` -------------------------------- ### Disable Example Checks Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/02-configuration.md Set `datadog_disable_example_checks` to true to remove all example checks provided with the Datadog Agent. ```yaml datadog_disable_example_checks: false ``` -------------------------------- ### Enable Network Performance Monitoring (NPM) Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/02-configuration.md Enable NPM by setting `network_config.enabled` to true in `system-probe.yaml`. This configuration is a dictionary. ```yaml network_config: enabled: true ``` -------------------------------- ### Review Datadog Agent Configuration Files Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/08-troubleshooting-reference.md View the actual Datadog Agent configuration files on different operating systems. Commands vary for Linux, Windows, and macOS. ```bash # Linux sudo cat /etc/datadog-agent/datadog.yaml ``` ```bash # Windows type %ProgramData%\Datadog\datadog.yaml ``` ```bash # macOS cat /opt/datadog-agent/etc/datadog.yaml ``` -------------------------------- ### Remove Legacy Datadog Installer Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/07-api-reference.md This Ansible playbook cleans up old Datadog installer packages. It detects and removes legacy packages if they are present. ```yaml Function: Clean up old datadog-installer package Input: None Output: Legacy packages removed Process: 1. Detect old installer package 2. Remove if present ``` -------------------------------- ### Skip Agent Installation on Specific Hosts Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/04-playbook-patterns.md Skips the Datadog Agent installation on hosts that are members of the `skip_agent_install` inventory group. This is controlled by the `datadog_windows_skip_install` variable. ```yaml --- - hosts: all become: yes roles: - datadog.dd.agent vars: datadog_api_key: "{{ vault_datadog_api_key }}" datadog_windows_skip_install: "{{ inventory_hostname in groups['skip_agent_install'] | default([]) }}" ``` -------------------------------- ### macOS Package Download URL Override Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/02-configuration.md Allows overriding the default download URL for the Datadog Agent DMG installer on macOS. Use this when providing a custom installer. ```yaml datadog_macos_download_url: "" ``` -------------------------------- ### APT Repository Configuration (Debian/Ubuntu) Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/02-configuration.md Defines the APT repository for Datadog on Debian/Ubuntu systems. If empty, the official Datadog repo is configured. Ensure GPG keys are correctly signed and located. ```yaml datadog_apt_repo: "deb [signed-by=/usr/share/keyrings/datadog-archive-keyring.gpg] https://apt.datadoghq.com/ stable 7" ``` -------------------------------- ### Multiple Checks with Instances Configuration Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/04-playbook-patterns.md Creates configuration files for multiple Datadog checks (process, nginx, postgres) with specific instances and parameters. ```yaml --- - hosts: all become: yes roles: - datadog.dd.agent vars: datadog_api_key: "YOUR_API_KEY" datadog_checks: process: init_config: instances: - name: ssh search_string: ['ssh', 'sshd'] - name: syslog search_string: ['rsyslog'] cpu_check_interval: 0.2 exact_match: true nginx: init_config: instances: - nginx_status_url: http://localhost/nginx_status/ tags: - "source:nginx" postgres: init_config: instances: - host: localhost port: 5432 username: datadog password: "{{ datadog_postgres_password }}" ``` -------------------------------- ### Enable Datadog System Probe (NPM/Security) Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/04-playbook-patterns.md Enables live processes, Network Performance Monitoring (NPM), and runtime security features. Configure sensitive words to be scrubbed from process arguments. ```yaml --- - hosts: all become: yes roles: - datadog.dd.agent vars: datadog_api_key: "YOUR_API_KEY" datadog_config: process_config: enabled: "true" scrub_args: true custom_sensitive_words: - consul_token - dd_api_key network_config: enabled: true runtime_security_config: enabled: true system_probe_other_config: traceroute: enabled: true ``` -------------------------------- ### Remove Integration Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/04-playbook-patterns.md Removes a previously installed integration. Use the `remove` action for the desired integration. ```yaml --- - hosts: all become: yes roles: - datalog.dd.agent vars: datadog_api_key: "YOUR_API_KEY" datadog_integration: datadog-postgresql: action: remove ``` -------------------------------- ### Ansible Collection Requirements File Source: https://github.com/ansible-collections/datadog/blob/main/README.md Include the Datadog collection in your `requirements.yml` file for automated installation. ```yaml collections: - name: datadog.dd ``` -------------------------------- ### Run Ansible-Lint to Show Human-Readable FQCN Errors Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/03-task-system.md Command to run ansible-lint, focusing on FQCN errors and displaying the output in a human-readable format. ```bash # Show human-readable output ansible-lint -t fqcn roles/ ``` -------------------------------- ### List Available Invoke Tasks Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/03-task-system.md Use this command to see all tasks defined in the invoke system. ```bash invoke --list ``` -------------------------------- ### Specify Windows Collection in Requirements Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/08-troubleshooting-reference.md Alternatively, declare the `ansible.windows` collection in your `requirements.yml` file for project-specific installations. ```yaml collections: - name: ansible.windows ``` -------------------------------- ### Verify Datadog Configuration Files Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/08-troubleshooting-reference.md Check if the Datadog configuration files have been created in the expected directories for Linux, Windows, or macOS. ```bash # Linux ls -la /etc/datadog-agent/ cat /etc/datadog-agent/datadog.yaml # Windows dir %ProgramData%\Datadog\ type %ProgramData%\Datadog\datadog.yaml # macOS ls -la /opt/datadog-agent/etc/ cat /opt/datadog-agent/etc/datadog.yaml ``` -------------------------------- ### Configure Internal APT Repository Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/06-platform-specifics.md Specify a custom internal mirror URL for the Datadog APT repository on Debian-based systems. ```yaml datadog_apt_repo: "deb https://internal-mirror/datadog stable 7" ``` -------------------------------- ### Specify Community General Collection in Requirements Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/08-troubleshooting-reference.md Declare the `community.general` collection in your `requirements.yml` file for installation on SUSE hosts. ```yaml collections: - name: community.general ``` -------------------------------- ### Enable Remote Updates via datadog-installer Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/02-configuration.md Set this boolean variable to enable remote installation and updates managed by the datadog-installer. ```yaml datadog_remote_updates: true ``` -------------------------------- ### Windows Playbook Configuration Source: https://github.com/ansible-collections/datadog/blob/main/roles/agent/README.md Playbook configuration specifically for Windows hosts, omitting `become: yes`. This method should only be used if the playbook exclusively targets Windows. ```yaml - hosts: servers roles: - { role: datadog.datadog } vars: ... ``` -------------------------------- ### Check File Permissions Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/08-troubleshooting-reference.md Verify that the Datadog configuration file has the correct read permissions for the `dd-agent` user on Linux. ```bash # Linux stat /etc/datadog-agent/datadog.yaml # Should be readable by dd-agent user ``` -------------------------------- ### Run Ansible-Lint to Show All FQCN Errors Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/03-task-system.md Command to run ansible-lint, specifically targeting FQCN errors and outputting results in JSON format. ```bash # Show all FQCN errors ansible-lint -t fqcn -x yaml -f json roles/ ``` -------------------------------- ### Verify Agent Version Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/08-troubleshooting-reference.md Use this command to check the installed Datadog Agent version. Ensure it is greater than or equal to 6.8 for integration compatibility. ```bash datadog-agent version # Must be >= 6.8 ``` -------------------------------- ### Check apt lock file Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/08-troubleshooting-reference.md This command lists processes that have the apt lists lock file open, helping to identify blocking processes. ```bash sudo lsof /var/lib/apt/lists/lock ``` -------------------------------- ### Override Old CentOS Python 3 Error Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/08-troubleshooting-reference.md If DNF is installed on older CentOS/RHEL systems, you can override the Python 3 compatibility check. ```yaml vars: datadog_ignore_old_centos_python3_error: true ``` -------------------------------- ### Debian Stretch apt_key Dependency Source: https://github.com/ansible-collections/datadog/blob/main/roles/agent/README.md On Debian Stretch, the `apt_key` module requires the `dirmngr` package. Ensure this dependency is installed before using the role. ```yaml --- - hosts: all pre_tasks: - name: Debian Stretch requires the dirmngr package to use apt_key become: yes apt: name: dirmngr state: present roles: - { role: datadog.datadog, become: yes } vars: datadog_api_key: "" ``` -------------------------------- ### Configure Datadog Agent Settings Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/02-configuration.md Use `datadog_config` to pass YAML configurations directly to `datadog.yaml` or `datadog.conf`. Refer to the datadog-agent config template for valid options. ```yaml datadog_config: log_level: DEBUG apm_config: enabled: true logs_enabled: true ``` -------------------------------- ### Enable Datadog Configuration Management Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/08-troubleshooting-reference.md Ensure the `datadog_manage_config` variable is set to `true` to allow configuration file management. ```yaml vars: datadog_manage_config: true # Must be true ``` -------------------------------- ### Importing Datadog Agent Role Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/05-file-structure.md Shows how to import the Datadog Agent role using both the collection format and the standalone role format. ```yaml # Collection format - import_role: name: datadog.dd.agent # Standalone format (from datadog.datadog role) - role: datadog.datadog ``` -------------------------------- ### Enable Traceroute in System Probe Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/02-configuration.md Enable the traceroute functionality for the system probe by setting `traceroute.enabled` to true. This configuration is at the top level of `system-probe.yaml` and is not nested. ```yaml system_probe_other_config: traceroute: enabled: true ``` -------------------------------- ### Check Windows volume information Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/08-troubleshooting-reference.md Display information about the available disk volumes on the Windows system. This is useful for checking disk space before MSI installation. ```powershell Get-Volume ``` -------------------------------- ### Verify Check Configuration File Creation Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/08-troubleshooting-reference.md Check if the specific check configuration file exists within the `conf.d` directory. ```bash ls /etc/datadog-agent/conf.d/ cat /etc/datadog-agent/conf.d/.d/conf.yaml ``` -------------------------------- ### Run Full Ansible-Lint Checks Source: https://github.com/ansible-collections/datadog/blob/main/_autodocs/03-task-system.md Command to execute all configured lint checks using ansible-lint on the specified roles directory. ```bash # Run full lint checks ansible-lint roles/ ``` -------------------------------- ### Uninstall Datadog Agent on Windows Source: https://github.com/ansible-collections/datadog/blob/main/roles/agent/README.md Ansible tasks to uninstall the Datadog Agent on Windows. It first checks if the agent is installed and then uses `win_package` to remove it if found. ```yaml - name: Check If Datadog Agent is installed win_shell: | (@(Get-ChildItem -Path "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" -Recurse) | Where {$_.GetValue("DisplayName") -like "Datadog Agent" }).PSChildName register: agent_installed_result - name: Set Datadog Agent installed fact set_fact: agent_installed: "{{ agent_installed_result.stdout | trim }}" - name: Uninstall the Datadog Agent win_package: product_id: "{{ agent_installed }}" state: absent when: agent_installed != "" ```