DataDog / ansible-datadog

Ansible role for Datadog Agent
Apache License 2.0
298 stars 222 forks source link

Breaks when in check mode #610

Closed tophitter closed 1 week ago

tophitter commented 1 month ago

When you run the new version with --check it failing due to conditional check as it can not find datadog_installer_install_result.failed

This is due to the include tasks to install for either DNF , YUM, DEB, and zypper get skipped when in check mode so the var datadog_installer_install_result.failed is not defined

tasks/installer-setup.yml ln 15 to 29

has this code `- name: Include installer DNF install task ansible.builtin.include_tasks: pkg-redhat/install-installer-dnf.yml when: ansible_facts.os_family in ["RedHat", "Rocky", "AlmaLinux"] and not ansible_check_mode and ansible_pkg_mgr == "dnf"

from what i can tell so far we could just remove the and not ansible_check_mode check from those lines and this will allow the check mode to run without error or we could use the not datadog_installer_install_result.failed | default(false) on the conditional check to stop it throwing a failed action maybe

also this only seem to fail on check mode when enable apm datadog_apm_instrumentation_enabled: "host" datadog_apm_instrumentation_libraries: ["all"]

the test playbook i used to get this error

`- hosts: localhost gather_facts: true tasks:

if we run this with no --check flag then it will work fine.

Command : ansible-playbook datadog.yml --diff --check Output: `TASK [datadog.dd.agent : Include installer DNF install task] ** skipping: [127.0.0.1]

TASK [datadog.dd.agent : Include installer YUM install task] ** skipping: [127.0.0.1]

TASK [datadog.dd.agent : Include installer DEB install task] ** skipping: [127.0.0.1]

TASK [datadog.dd.agent : Include installer Zypper install task] *** skipping: [127.0.0.1]

TASK [datadog.dd.agent : Bootstrap the installer] ***** fatal: [127.0.0.1]: FAILED! => {"msg": "The conditional check 'not datadog_installer_install_result.failed' failed. The error was: error while evaluating conditional (not datadog_installer_install_result.failed): 'datadog_installer_install_result' is undefined. 'datadog_installer_install_result' is undefined\n\nThe error appears to be in '/home/****/.ansible/collections/ansible_collections/datadog/dd/roles/agent/tasks/installer-setup.yml': line 31, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Bootstrap the installer\n ^ here\n"} ...ignoring`