Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ These variables provide additional configuration during the installation of the
| `datadog_windows_ddagentuser_name` | The name of Windows user to create/use, in the format `<domain>\<user>` (Windows only).|
| `datadog_windows_ddagentuser_password` | The password used to create the user and/or register the service (Windows only).|
| `datadog_apply_windows_614_fix` | Whether or not to download and apply file referenced by `datadog_windows_614_fix_script_url` (Windows only). See https://dtdg.co/win-614-fix for more details. You can set this to `false` assuming your hosts aren't running Datadog Agent 6.14.\*.|
| `datadog_windows_skip_install` | Set to `true` to force the role to skip Windows Agent installation even if the role detects that installation is required (Windows only).|
| `datadog_windows_force_reinstall` | Set to `true` to force the role to reinstall the Windows Agent regardless of the automatic feature detection logic (Windows only).|
| `datadog_macos_user` | The name of the user to run Agent under. The user has to exist, it won't be created automatically. Defaults to `ansible_user` (macOS only).|
| `datadog_macos_download_url` | Override the URL to download the DMG installer from (macOS only).|
| `datadog_apm_instrumentation_enabled` | Configure APM instrumentation. Possible values are: <br/> - `host`: Both the Agent and your services are running on a host. <br/> - `docker`: The Agent and your services are running in separate Docker containers on the same host.<br/>- `all`: Supports all the previous scenarios for `host` and `docker` at the same time.|
Expand Down
8 changes: 8 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@ datadog_windows_614_fix_script_url: "https://s3.amazonaws.com/ddagent-windows-st
# whether or not to download and apply the above fix
datadog_apply_windows_614_fix: true

# Force the role to skip reinstall steps on Windows, even if the Agent
# isn't detected yet.
datadog_windows_skip_install: false

# Force the role to reinstall the Agent on Windows regardless of the
# automatic feature checks. This can be used to downgrade the Agent on Windows.
datadog_windows_force_reinstall: false

# Override to change the name of the windows user to create
datadog_windows_ddagentuser_name: ""
# Override to change the password of the created windows user.
Expand Down
17 changes: 17 additions & 0 deletions tasks/parse-version-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,20 @@
failed_when: false
check_mode: false
when: ansible_facts.os_family == "Windows"

- name: Parse installed Windows Agent version into components
ansible.builtin.set_fact:
agent_datadog_installed_version: "{{ agent_datadog_version_check_win.stdout | trim |
regex_search(installed_agent_regexp, '\\g<major>', '\\g<minor>', '\\g<bugfix>') }}"
vars:
installed_agent_regexp: (?P<major>[0-9]+)\.(?P<minor>[0-9]+)\.(?P<bugfix>[0-9]+)
when: >-
ansible_facts.os_family == "Windows" and
agent_datadog_version_check_win.stdout | trim | length > 0

- name: Set installed version component vars
ansible.builtin.set_fact:
agent_datadog_installed_major: "{{ agent_datadog_installed_version.0 | default('', true) | string }}"
agent_datadog_installed_minor: "{{ agent_datadog_installed_version.1 | default('', true) | string }}"
agent_datadog_installed_bugfix: "{{ agent_datadog_installed_version.2 | default('', true) | string }}"
when: ansible_facts.os_family == "Windows" and agent_datadog_version_check_win.stdout | trim | length > 0
36 changes: 36 additions & 0 deletions tasks/pkg-windows-opts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,39 @@
when: >-
(agent_datadog_skip_install and (agent_datadog_major | int <= 7) and (agent_datadog_minor | int < 45)) and
(("NPM" in agent_windows_active_features.stdout_lines) != agent_datadog_sysprobe_enabled)

# Check if downgrade is requested (installed version is higher than requested version)
- name: Initialize downgrade detection flag
ansible.builtin.set_fact:
agent_datadog_downgrade_detected: false

- name: Detect if downgrade is requested
ansible.builtin.set_fact:
agent_datadog_downgrade_detected: true
when: >-
agent_datadog_installed_major is defined and
agent_datadog_installed_minor is defined and
agent_datadog_installed_bugfix is defined and
(
(agent_datadog_installed_major | int > agent_datadog_major | int) or
(agent_datadog_installed_major | int == agent_datadog_major | int and
agent_datadog_installed_minor | int > agent_datadog_minor | int) or
(agent_datadog_installed_major | int == agent_datadog_major | int and
agent_datadog_installed_minor | int == agent_datadog_minor | int and
agent_datadog_installed_bugfix | int > agent_datadog_bugfix | int)
)

- name: Warn about downgrade
ansible.builtin.debug:
msg: >-
datadog_agent_version {{ agent_datadog_major }}.{{ agent_datadog_minor }}.{{ agent_datadog_bugfix }}
is lower than installed version
{{ agent_datadog_installed_major }}.{{ agent_datadog_installed_minor }}.{{ agent_datadog_installed_bugfix }},
proceeding to downgrade by uninstalling current version first
when: agent_datadog_downgrade_detected

- name: Force reinstall for downgrade
ansible.builtin.set_fact:
agent_datadog_skip_install: false
agent_datadog_force_reinstall: true
when: agent_datadog_downgrade_detected
53 changes: 50 additions & 3 deletions tasks/pkg-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@
- name: Include Windows opts tasks
ansible.builtin.include_tasks: pkg-windows-opts.yml

- name: Force skip install when requested
ansible.builtin.set_fact:
agent_datadog_skip_install: true
when: datadog_windows_skip_install | bool

- name: Force Agent reinstall when requested
ansible.builtin.set_fact:
agent_datadog_force_reinstall: true
agent_datadog_skip_install: false
when: datadog_windows_force_reinstall | bool

- name: Download windows datadog agent 614 fix script
ansible.windows.win_get_url:
url: "{{ datadog_windows_614_fix_script_url }}"
Expand Down Expand Up @@ -48,6 +59,37 @@
register: agent_download_msi_result
when: (not agent_datadog_skip_install) and (not ansible_check_mode)

- name: Look up installed Datadog Agent product ids when forcing reinstall
ansible.windows.win_shell: |
$productName = "Datadog Agent"
$uninstallRoots = @(
"HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall",
"HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
)
$productIds = foreach ($root in $uninstallRoots) {
if (-not (Test-Path $root)) {
continue
}
Get-ItemProperty "$root\*" -ErrorAction SilentlyContinue |
Where-Object { $_.DisplayName -clike $productName } |
Select-Object -ExpandProperty PSChildName
}
$productIds | Sort-Object -Unique
register: agent_datadog_installed_product_ids_result
changed_when: false
check_mode: false
when:
- not agent_datadog_skip_install
- agent_datadog_force_reinstall

- name: Cache installed product ids when available
ansible.builtin.set_fact:
agent_datadog_windows_installed_product_ids: "{{ agent_datadog_installed_product_ids_result.stdout_lines | select('match', '.+') | list }}"
when:
- not agent_datadog_skip_install
- agent_datadog_force_reinstall
- agent_datadog_installed_product_ids_result.stdout_lines | length > 0

- name: Create Binary directory root (if not default)
ansible.windows.win_file:
path: "{{ datadog_windows_program_files_dir }}"
Expand Down Expand Up @@ -76,11 +118,16 @@
when: datadog_windows_ddagentuser_password | default('', true) | length > 0
no_log: true

- name: Uninstall agent to update optional features
- name: Uninstall installed Datadog Agent to update optional features or downgrade or because requested
ansible.windows.win_package:
path: "{{ agent_download_msi_result.dest }}"
product_id: "{{ item }}"
state: absent
when: not agent_datadog_skip_install and agent_datadog_force_reinstall
loop: "{{ agent_datadog_windows_installed_product_ids }}"
when:
- not agent_datadog_skip_install
- agent_datadog_force_reinstall
- agent_datadog_windows_installed_product_ids is defined
- agent_datadog_windows_installed_product_ids | length > 0

- name: Install downloaded agent
ansible.windows.win_package:
Expand Down