Skip to content

Commit

Permalink
Fix Windows handlers definition (#349)
Browse files Browse the repository at this point in the history
Dynamically includes the Windows Agent restart handler to make it work as expected.
  • Loading branch information
KSerrania authored Apr 21, 2021
1 parent 2e4b4ba commit f9fb051
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
9 changes: 6 additions & 3 deletions handlers/main-win.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
---

- name: restart datadog-agent-win
# This file doesn't actually contain "handlers" in the Ansible sense: when running
# our role, Ansible only loads the contents of handlers/main.yml as handlers.
# However, this is here because this is a "handler-like" task that is dynamically
# included by a handler task in handlers/main.yml.
- name: Restart Windows datadogagent service
win_service:
name: datadogagent
state: restarted
force_dependent_services: true
when: datadog_enabled and not ansible_check_mode
when: datadog_enabled and not ansible_check_mode and ansible_facts.os_family == "Windows"
11 changes: 9 additions & 2 deletions handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,12 @@
state: restarted
when: datadog_enabled and not ansible_check_mode and not ansible_facts.os_family == "Windows"

- include_tasks: handlers/main-win.yml
when: ansible_facts.os_family == "Windows"
# We can't add the Windows Agent service restart handler directly here because that makes the role require
# the ansible.windows collection on all platforms. We only want it to be needed on Windows.
# Therefore, what we do is the following: when needed, our Windows tasks call this handler to require a
# Windows Agent restart (through notify: restart datadog-agent-win).
# When notified, the below handler is executed at the end of the playbook run.
# The include_tasks loads the handlers/main-win.yml file, which contains the real service restart task
# (which depends on ansible.windows), and runs it, triggering the Windows Agent restart.
- name: restart datadog-agent-win
include_tasks: handlers/main-win.yml

0 comments on commit f9fb051

Please sign in to comment.