diff --git a/README.md b/README.md index 1f674619..4b3b1c55 100644 --- a/README.md +++ b/README.md @@ -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 `\` (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:
- `host`: Both the Agent and your services are running on a host.
- `docker`: The Agent and your services are running in separate Docker containers on the same host.
- `all`: Supports all the previous scenarios for `host` and `docker` at the same time.| diff --git a/defaults/main.yml b/defaults/main.yml index 69f0e6c9..8f29ca32 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -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. diff --git a/tasks/pkg-windows.yml b/tasks/pkg-windows.yml index c27b8376..c39b48a7 100644 --- a/tasks/pkg-windows.yml +++ b/tasks/pkg-windows.yml @@ -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 }}" @@ -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 }}" @@ -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: