Skip to content

Commit

Permalink
Align windows agent to linux so that service is disabled on when data…
Browse files Browse the repository at this point in the history
…dog_enabled false (#338)

This includes several proposed modifications:

Reorder the services in the stop_services task so that when they are shut down, they don't have dependency issues due to shutdown order of operations
Disable services rather than stopping them when datadog_enabled is false
Ensure services are not set to disabled when datadog_enabled is true
Resolve/compute datadog_tracked_checks within the task sequence as set_fact rather than only with the default vars so that its variable precedence is higher than include_vars. Also address null/none dictionary during this step. Propose calling it sanitize-checks.

Co-authored-by: Kylian Serrania <[email protected]>
  • Loading branch information
erikhjensen and KSerrania authored Apr 9, 2021
1 parent cfabc48 commit a12a1dd
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
3 changes: 0 additions & 3 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ datadog_additional_checks: []
# set this to `true` to delete default checks
datadog_disable_default_checks: false

# default tracked checks
datadog_tracked_checks: "{{ datadog_checks | list + datadog_additional_checks }}"

# default user/group
datadog_user: dd-agent
datadog_group: dd-agent
Expand Down
16 changes: 13 additions & 3 deletions tasks/agent-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@
with_items: "{{ datadog_checks|list }}"
notify: restart datadog-agent-win

- name: Ensure datadog-trace-agent and datadog-process-agent are not disabled
win_service:
name: "{{ item }}"
start_mode: manual
when: not datadog_skip_running_check and datadog_enabled and not ansible_check_mode
with_list:
- datadog-trace-agent
- datadog-process-agent

- name: Create system-probe configuration file
win_template:
src: system-probe.yaml.j2
Expand All @@ -64,15 +73,16 @@
start_mode: auto
when: not datadog_skip_running_check and datadog_enabled and not ansible_check_mode

- name: Ensure datadog-agent is not running
- name: Ensure datadog-agent is disabled
win_service:
name: "{{ item }}"
state: stopped
start_mode: disabled
when: not datadog_skip_running_check and not datadog_enabled
with_list:
- datadogagent
- datadog-process-agent
- datadog-trace-agent
- datadog-process-agent
- datadogagent

- name: Create installation information file
template:
Expand Down
3 changes: 3 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
- name: Check if OS is supported
include_tasks: os-check.yml

- name: Resolve datadog_tracked_checks later to defend against variable presidence issues arising from dynamically included null datadog_checks
include_tasks: sanitize-checks.yml

- name: Set Facts for Datadog Agent Major Version
include_tasks: set-parse-version.yml

Expand Down
8 changes: 8 additions & 0 deletions tasks/sanitize-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- name: Defend against defined but null datadog_checks variable
set_fact:
datadog_checks: "{{ datadog_checks | default({}, true) }}"

- name: Resolve datadog_tracked_checks
set_fact:
datadog_tracked_checks: "{{ datadog_checks | list + datadog_additional_checks | default([], true) }}"

0 comments on commit a12a1dd

Please sign in to comment.