I’m new to Ansible and am trying to use data from querying a postgres DB to write out a
Datadog agent config. I’ve figured out 1) how to retrieve the data from postgres and 2) write out a single static node’s agent config, but I haven’t figured out how to tie the two together. Any help would be GREATLY appreciated.
Here's my code:
---
- name: Manage Datadog agent config for Oracle DBs
hosts: localhost
roles:
- { role: datadog.datadog, become: yes}
tasks:
- name: Get list of DBs from inventory DB
community.postgresql.postgresql_query:
db: inventory
login_user: "{{ ansible_user_id }}"
query: SELECT DISTINCT db_name, env_type, db_domain FROM stg_db WHERE env_type = 'prod' LIMIT 1
search_path: inventory
register: db_list
- name: Get server string
community.postgresql.postgresql_query:
db: inventory
login_user: "{{ ansible_user_id }}"
query: SELECT unique_name, server_name from dg_member WHERE database_role = 'primary' and db_name = '{{ item.db_name }}'
search_path: inventory
loop: "{{ db_list['query_result'] }}"
loop_control:
label:
register: server_metadata
- name: Configure Datadog agent
datadog_checks:
oracle:
init_config:
instances:
- empty_default_hostname: true
min_collection_interval: 60
password: "{{ datadog_password }}"
protocol: TCP
server: "{{ server_name }}.{{ db_domain }}:1521"
service_name: “{{ unique_name }}.{{ db_domain }}
tags:
- “env:{{ env }}”
use_global_custom_queries: 'false'
username: "{{ datadog_username }}"
loop: "{{ server_metadata.results }}"
vars:
datadog_api_key: “example”
db_domain: "{{ item.item.db_domain }}"
env: "{{ item.item.env_type }}"
datadog_password: “example”
datadog_username: “example”
db_name: "{{ item.item.db_name }}"
server_name: "{{ item.query_result.0.server_name }}"
unique_name: "{{ item.query_result.0.unique_name }}"
And, here's the full error:
ERROR! couldn't resolve module/action 'datadog_checks'. This often indicates a misspelling, missing collection, or incorrect module path.
The error appears to be in '/home/s175827/ansible/test.yaml': line 28, column 7, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: Configure Datadog agent
^ here