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: