Skip to content

Commit

Permalink
Fix checks delete (#320)
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
albertvaka authored Jan 8, 2021
1 parent bbc14e8 commit 84f8303
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
8 changes: 6 additions & 2 deletions tasks/agent-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
14 changes: 9 additions & 5 deletions tasks/agent-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
13 changes: 9 additions & 4 deletions tasks/agent5-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@
- 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

- 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
Expand All @@ -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:
Expand Down

0 comments on commit 84f8303

Please sign in to comment.