From 84f83036fdb32bea5838298a0dd9aaf70d221aa1 Mon Sep 17 00:00:00 2001 From: Albert Vaca Cintora Date: Fri, 8 Jan 2021 20:49:03 +0100 Subject: [PATCH] Fix checks delete (#320) - Missing state: absent in a couple places. - Ansible on Windows needs win_basename and win_file. - pattern should be patterns. - Make datadog_disable_default_checks not delete checks in datadog_additional_checks. - Restart the agent if checks were deleted. - Make linter happy. --- tasks/agent-linux.yml | 8 ++++++-- tasks/agent-win.yml | 14 +++++++++----- tasks/agent5-linux.yml | 13 +++++++++---- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/tasks/agent-linux.yml b/tasks/agent-linux.yml index a9161774..cbe0ca2f 100644 --- a/tasks/agent-linux.yml +++ b/tasks/agent-linux.yml @@ -24,7 +24,8 @@ - name: Register all checks directories present in datadog find: paths: /etc/datadog-agent/conf.d/ - pattern: "*.d" + patterns: + - "*.d" file_type: directory register: datadog_conf_directories when: datadog_disable_untracked_checks or datadog_disable_default_checks @@ -35,12 +36,15 @@ state: absent loop: "{{ datadog_conf_directories.files | map(attribute='path') | list | map('basename') | list | map('regex_replace', '^(.*).d$', '\\1') | list }}" when: datadog_disable_untracked_checks and item not in datadog_tracked_checks + notify: restart datadog-agent - name: Delete all default checks file: path: "/etc/datadog-agent/conf.d/{{ item }}.d/conf.yaml.default" + state: absent loop: "{{ datadog_conf_directories.files | map(attribute='path') | list | map('basename') | list | map('regex_replace', '^(.*).d$', '\\1') | list }}" - when: datadog_disable_default_checks + when: datadog_disable_default_checks and item not in datadog_tracked_checks + notify: restart datadog-agent - name: Ensure configuration directories are present for each Datadog check file: diff --git a/tasks/agent-win.yml b/tasks/agent-win.yml index 63f62982..133e448b 100644 --- a/tasks/agent-win.yml +++ b/tasks/agent-win.yml @@ -8,7 +8,8 @@ - name: Register all checks directories present in datadog win_find: paths: "{{ ansible_facts.env['ProgramData'] }}\\Datadog\\conf.d" - pattern: "*.d" + patterns: + - "*.d" file_type: directory register: datadog_conf_directories when: datadog_disable_untracked_checks or datadog_disable_default_checks @@ -17,14 +18,17 @@ win_file: path: "{{ ansible_facts.env['ProgramData'] }}\\Datadog\\conf.d\\{{ item }}.d\\conf.yaml" state: absent - loop: "{{ datadog_conf_directories.files | map(attribute='path') | list | map('basename') | list | map('regex_replace', '^(.*).d$', '\\1') | list }}" + loop: "{{ datadog_conf_directories.files | map(attribute='path') | list | map('win_basename') | list | map('regex_replace', '^(.*).d$', '\\1') | list }}" when: datadog_disable_untracked_checks and item not in datadog_tracked_checks + notify: restart datadog-agent-win - name: Delete default checks - file: + win_file: path: "{{ ansible_facts.env['ProgramData'] }}\\Datadog\\conf.d\\{{ item }}.d\\conf.yaml.default" - loop: "{{ datadog_conf_directories.files | map(attribute='path') | list | map('basename') | list | map('regex_replace', '^(.*).d$', '\\1') | list }}" - when: datadog_disable_default_checks + state: absent + loop: "{{ datadog_conf_directories.files | map(attribute='path') | list | map('win_basename') | list | map('regex_replace', '^(.*).d$', '\\1') | list }}" + when: datadog_disable_default_checks and item not in datadog_tracked_checks + notify: restart datadog-agent-win - name: Ensure configuration directories are present for each Datadog check win_file: diff --git a/tasks/agent5-linux.yml b/tasks/agent5-linux.yml index f6d3bc14..66ed5b6b 100644 --- a/tasks/agent5-linux.yml +++ b/tasks/agent5-linux.yml @@ -29,7 +29,8 @@ - name: Register all checks files present in datadog find: paths: /etc/dd-agent/conf.d/ - pattern: "*.yaml" + patterns: + - "*.yaml" file_type: file register: datadog_conf_files when: datadog_disable_untracked_checks @@ -37,7 +38,8 @@ - name: Register all checks files present in datadog find: paths: /etc/dd-agent/conf.d/ - pattern: "*.yaml.default" + patterns: + - "*.yaml.default" file_type: file register: datadog_conf_files_default when: datadog_disable_default_checks @@ -48,13 +50,16 @@ state: absent loop: "{{ datadog_conf_files.files | map(attribute='path') | list | map('basename') | list | map('regex_replace', '^(.*).yaml$', '\\1') | list }}" when: datadog_disable_untracked_checks and item not in datadog_tracked_checks + notify: restart datadog-agent - name: Delete default checks file: path: "/etc/dd-agent/conf.d/{{ item }}.yaml.default" state: absent - loop: "{{ datadog_conf_files_default.files | map(attribute='path') | list | map('basename') | list | map('regex_replace', '^(.*).yaml.default$', '\\1') | list }}" - when: datadog_disable_default_checks + loop: "{{ datadog_conf_files_default.files | map(attribute='path') | list + | map('basename') | list | map('regex_replace', '^(.*).yaml.default$', '\\1') | list }}" + when: datadog_disable_default_checks and item not in datadog_tracked_checks + notify: restart datadog-agent - name: (agent5) Create a configuration file for each Datadog check template: