After you’ve installed the collection, you’ll need to create an inventory that specifies the hosts you want to monitor with Datadog. In the example below, we’ve created a simple inventory (
inventory.yaml
) using a mix of host names and IP addresses. Grouping your hosts by
web
,
databases
, and
prod
enable you to create and run playbooks that apply only to hosts in these subfields.
You can also create a dynamic inventory by using cloud provider tags to define the scope of your inventory; this ensures that the inventory will automatically update as new hosts are created. If you use AWS, you can
check out this blog post
to learn how to install Datadog on your EC2 hosts by creating a dynamic inventory.
Now that we have an inventory, it’s time to create our playbook (
datadog_playbook.yaml
) that installs the Agent on our inventory of hosts. We accomplish this by importing the Datadog role as shown below. In our example, we provide the Datadog API key as a string—however, we recommend encrypting your credentials with a solution such as
Ansible Vault
.
datadog_playbook.yaml
- name:Install the Datadog Agent import_role:name:datadog.dd.agentvars:datadog_api_key:"<YOUR_API_KEY>"
We can now apply our playbook to our inventory. To install the Datadog Agent on all hosts within our
inventory.yaml
file, we can run the following command on our control node:
You can also easily configure your playbook to install Datadog integrations so you can gain full visibility across your environment. To learn more, check out our
documentation for the
agent
role
.