Skip to content

Commit ea320e0

Browse files
Pull ansible-datadog (#155)
Co-authored-by: GitHub Actions Bot <>
1 parent 30ea2af commit ea320e0

File tree

7 files changed

+116
-15
lines changed

7 files changed

+116
-15
lines changed

roles/agent/handlers/main-win.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
name: datadogagent
99
state: restarted
1010
force_dependent_services: true
11-
when: datadog_enabled and not ansible_check_mode and ansible_facts.os_family == "Windows"
11+
when: datadog_enabled and not ansible_check_mode and ansible_facts.os_family == "Windows" and not datadog_remote_update_in_progress

roles/agent/tasks/agent-win.yml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
ansible.windows.win_service:
9090
name: "{{ item }}"
9191
start_mode: manual
92-
when: not datadog_skip_running_check and datadog_enabled and not ansible_check_mode
92+
when: not datadog_skip_running_check and datadog_enabled and not ansible_check_mode and not datadog_remote_update_in_progress
9393
with_list:
9494
- datadog-trace-agent
9595
- datadog-process-agent
@@ -106,22 +106,33 @@
106106
ansible.windows.win_service:
107107
name: datadogagent
108108
register: datadog_service_info
109-
when: not datadog_skip_running_check and datadog_enabled and not ansible_check_mode
109+
when: not datadog_skip_running_check and datadog_enabled and not ansible_check_mode and not datadog_remote_update_in_progress
110110

111111
- name: Ensure datadog-agent is running
112112
ansible.windows.win_service:
113113
name: datadogagent
114114
state: started
115115
start_mode: delayed
116-
when: not datadog_skip_running_check and datadog_enabled and not ansible_check_mode and datadog_service_info.exists
116+
when:
117+
- not datadog_skip_running_check
118+
- datadog_enabled
119+
- not ansible_check_mode
120+
- (datadog_service_info.exists | default(false))
121+
- not datadog_remote_update_in_progress
117122
failed_when: false
118123
register: datadog_start_result
119124

120125
- name: Wait and retry if service failed to start
121126
ansible.windows.win_service:
122127
name: datadogagent
123128
state: started
124-
when: not datadog_skip_running_check and datadog_enabled and not ansible_check_mode and datadog_service_info.exists and datadog_start_result.failed
129+
when:
130+
- not datadog_skip_running_check
131+
- datadog_enabled
132+
- not ansible_check_mode
133+
- (datadog_service_info.exists | default(false))
134+
- (datadog_start_result.failed | default(false))
135+
- not datadog_remote_update_in_progress
125136
delay: 10
126137
retries: 3
127138

@@ -130,7 +141,7 @@
130141
name: "{{ item }}"
131142
state: stopped
132143
start_mode: disabled
133-
when: not datadog_skip_running_check and not datadog_enabled
144+
when: not datadog_skip_running_check and not datadog_enabled and not datadog_remote_update_in_progress
134145
with_list:
135146
- datadog-trace-agent
136147
- datadog-process-agent

roles/agent/tasks/main.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
- name: Check if OS is supported
1515
ansible.builtin.include_tasks: os-check.yml
1616

17+
# Check for Windows remote updates before proceeding with installation
18+
- name: Windows remote update check
19+
ansible.builtin.include_tasks: windows_remote_update_check.yml
20+
when: ansible_facts.os_family == "Windows"
21+
1722
- name: Fail if API key is missing
1823
ansible.builtin.fail:
1924
msg: "datadog_api_key is mandatory when using managed config"
@@ -64,11 +69,21 @@
6469
ansible.builtin.include_tasks: pkg-suse.yml
6570
when: ansible_facts.os_family == "Suse"
6671

72+
# Windows variable initialization - always needed for configuration
73+
- name: Set windows NPM installed
74+
ansible.builtin.set_fact:
75+
agent_datadog_sysprobe_enabled: "{{ network_config is defined and 'enabled' in (network_config | default({}, true)) and network_config['enabled'] }}"
76+
when: ansible_facts.os_family == "Windows"
77+
78+
- name: Include Windows opts tasks
79+
ansible.builtin.include_tasks: pkg-windows-opts.yml
80+
when: ansible_facts.os_family == "Windows"
81+
6782
# Note we don't check agent_datadog_skip_install variable value for windows here,
6883
# because some tasks in pkg-windows.yml are carried out regardless of its value.
6984
- name: Windows Install Tasks
7085
ansible.builtin.include_tasks: pkg-windows.yml
71-
when: ansible_facts.os_family == "Windows"
86+
when: ansible_facts.os_family == "Windows" and not datadog_remote_update_in_progress
7287

7388
- name: MacOS Install Tasks
7489
ansible.builtin.include_tasks: pkg-macos.yml

roles/agent/tasks/parse-version-windows.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,20 @@
1919
failed_when: false
2020
check_mode: false
2121
when: ansible_facts.os_family == "Windows"
22+
23+
- name: Parse installed Windows Agent version into components
24+
ansible.builtin.set_fact:
25+
agent_datadog_installed_version: "{{ agent_datadog_version_check_win.stdout | trim |
26+
regex_search(installed_agent_regexp, '\\g<major>', '\\g<minor>', '\\g<bugfix>') }}"
27+
vars:
28+
installed_agent_regexp: (?P<major>[0-9]+)\.(?P<minor>[0-9]+)\.(?P<bugfix>[0-9]+)
29+
when: >-
30+
ansible_facts.os_family == "Windows" and
31+
agent_datadog_version_check_win.stdout | trim | length > 0
32+
33+
- name: Set installed version component vars
34+
ansible.builtin.set_fact:
35+
agent_datadog_installed_major: "{{ agent_datadog_installed_version.0 | default('', true) | string }}"
36+
agent_datadog_installed_minor: "{{ agent_datadog_installed_version.1 | default('', true) | string }}"
37+
agent_datadog_installed_bugfix: "{{ agent_datadog_installed_version.2 | default('', true) | string }}"
38+
when: ansible_facts.os_family == "Windows" and agent_datadog_version_check_win.stdout | trim | length > 0

roles/agent/tasks/pkg-windows-opts.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,41 @@
125125
when: >-
126126
(agent_datadog_skip_install and (agent_datadog_major | int <= 7) and (agent_datadog_minor | int < 45)) and
127127
(("NPM" in agent_windows_active_features.stdout_lines) != agent_datadog_sysprobe_enabled)
128+
129+
# Check if downgrade is requested (installed version is higher than requested version)
130+
- name: Initialize downgrade detection flag
131+
ansible.builtin.set_fact:
132+
agent_datadog_downgrade_detected: false
133+
134+
- name: Detect if downgrade is requested
135+
ansible.builtin.set_fact:
136+
agent_datadog_downgrade_detected: true
137+
when: >-
138+
agent_datadog_installed_major is defined and
139+
agent_datadog_installed_minor is defined and
140+
agent_datadog_installed_bugfix is defined and
141+
(
142+
(agent_datadog_installed_major | int > agent_datadog_major | int) or
143+
(agent_datadog_installed_major | int == agent_datadog_major | int and
144+
agent_datadog_installed_minor | int > agent_datadog_minor | int) or
145+
(agent_datadog_installed_major | int == agent_datadog_major | int and
146+
agent_datadog_installed_minor | int == agent_datadog_minor | int and
147+
agent_datadog_installed_bugfix | int > agent_datadog_bugfix | int)
148+
)
149+
150+
# Skip downgrade warning if remote update is in progress
151+
- name: Warn about downgrade
152+
ansible.builtin.debug:
153+
msg: >-
154+
datadog_agent_version {{ agent_datadog_major }}.{{ agent_datadog_minor }}.{{ agent_datadog_bugfix }}
155+
is lower than installed version
156+
{{ agent_datadog_installed_major }}.{{ agent_datadog_installed_minor }}.{{ agent_datadog_installed_bugfix }},
157+
proceeding to downgrade by uninstalling current version first
158+
when: agent_datadog_downgrade_detected and not datadog_remote_update_in_progress
159+
160+
# We do not need to check for remote update in progress here because installation is skipped if remote update is in progress anyway
161+
- name: Force reinstall for downgrade
162+
ansible.builtin.set_fact:
163+
agent_datadog_skip_install: false
164+
agent_datadog_force_reinstall: true
165+
when: agent_datadog_downgrade_detected

roles/agent/tasks/pkg-windows.yml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
---
2-
## must be prior to `pkg-windows-opts.yml`, because the variable is used inside
3-
- name: Set windows NPM installed
4-
ansible.builtin.set_fact:
5-
agent_datadog_sysprobe_enabled: "{{ network_config is defined and 'enabled' in (network_config | default({}, true)) and network_config['enabled'] }}"
6-
7-
## Might override agent_datadog_skip_install
8-
- name: Include Windows opts tasks
9-
ansible.builtin.include_tasks: pkg-windows-opts.yml
2+
# Note: Windows opts tasks and NPM setup are now included in main.yml to ensure variables are set even during remote updates
103

114
- name: Force skip install when requested
125
ansible.builtin.set_fact:
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
- name: Initialize remote update flag
3+
ansible.builtin.set_fact:
4+
datadog_remote_update_in_progress: false
5+
6+
- name: Check if remote update is in progress
7+
ansible.windows.win_shell: |
8+
Get-CimInstance Win32_Process | Where-Object {
9+
$_.Name -eq "datadog-installer.exe" -and
10+
$_.CommandLine -match "postStartExperimentBackground"
11+
}
12+
register: remote_update_check
13+
14+
- name: Update remote update flag if installer is running
15+
ansible.builtin.set_fact:
16+
datadog_remote_update_in_progress: true
17+
when:
18+
- remote_update_check.stdout is defined
19+
- remote_update_check.stdout | trim | length > 0
20+
21+
- name: Inform about remote update in progress
22+
ansible.builtin.debug:
23+
msg: >-
24+
Remote update is in progress. Skipping installation and restart of the Agent.
25+
Any changes to the configuration will only take effect at the next Agent restart,
26+
either manually or through a future role execution.
27+
when: datadog_remote_update_in_progress

0 commit comments

Comments
 (0)