From a9d142388908796f18f9e7afb9baa8eb0cbc5b07 Mon Sep 17 00:00:00 2001 From: Alex Lopez Date: Thu, 7 Mar 2024 10:51:14 +0100 Subject: [PATCH 1/5] Limit the versions of the agent that can be installed on Centos < 7 --- tasks/set-parse-version.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tasks/set-parse-version.yml b/tasks/set-parse-version.yml index 79ed10de..1733fdbd 100644 --- a/tasks/set-parse-version.yml +++ b/tasks/set-parse-version.yml @@ -7,10 +7,20 @@ set_fact: agent_datadog_skip_install: false +- name: Upper bound for last supported Agent version in older RedHat version when latest version is expected + set_fact: + datadog_agent_version: "{{ datadog_agent_major_version | default('7', true) }}.51.1" + when: ansible_facts.os_family == "RedHat" and (ansible_facts.distribution_major_version | int) < 7 and datadog_agent_version | length == 0 + - name: Include parse version tasks include_tasks: parse-version.yml when: datadog_agent_version | default('', true) | length > 0 +- name: Fail if specified agent full version is not supported by OS (Centos < 7) + fail: + msg: "Agent versions {{ agent_datadog_major }}.52 and above require Centos >= 7 or equivalent" + when: ansible_facts.os_family == "RedHat" and (ansible_facts.distribution_major_version | int) < 7 and (agent_datadog_minor | int) >= 52 + - name: Set Agent default major version set_fact: agent_datadog_agent_major_version: "7" From 96a56df2288a95c5dd95c900d10d0dd15ab99563 Mon Sep 17 00:00:00 2001 From: Alex Lopez Date: Thu, 7 Mar 2024 11:42:52 +0100 Subject: [PATCH 2/5] Refactor version capping code --- tasks/os-check.yml | 7 +++++++ tasks/set-parse-version.yml | 12 ++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/tasks/os-check.yml b/tasks/os-check.yml index 1ec5898c..080eaae2 100644 --- a/tasks/os-check.yml +++ b/tasks/os-check.yml @@ -3,3 +3,10 @@ fail: msg: "The Datadog Ansible role does not support your OS yet. Please email support@datadoghq.com to open a feature request." when: ansible_facts.os_family not in ["RedHat", "Rocky", "AlmaLinux", "Debian", "Suse", "Windows", "Darwin"] + +- name: Upper bound last supported Agent version for Centos < 7 + set_fact: + datadog_agent_max_version: + full: "{{ datadog_agent_major_version | default('7', true) }}.51.1" + minor: 51 + when: ansible_facts.os_family == "RedHat" and (ansible_facts.distribution_major_version | int) < 7 diff --git a/tasks/set-parse-version.yml b/tasks/set-parse-version.yml index 1733fdbd..d1353845 100644 --- a/tasks/set-parse-version.yml +++ b/tasks/set-parse-version.yml @@ -7,19 +7,19 @@ set_fact: agent_datadog_skip_install: false -- name: Upper bound for last supported Agent version in older RedHat version when latest version is expected +- name: Apply upper bound for last supported Agent version when latest version is expected set_fact: - datadog_agent_version: "{{ datadog_agent_major_version | default('7', true) }}.51.1" - when: ansible_facts.os_family == "RedHat" and (ansible_facts.distribution_major_version | int) < 7 and datadog_agent_version | length == 0 + datadog_agent_version: "{{ datadog_agent_max_version.full }}" + when: datadog_agent_max_version is defined and datadog_agent_version | length == 0 - name: Include parse version tasks include_tasks: parse-version.yml when: datadog_agent_version | default('', true) | length > 0 -- name: Fail if specified agent full version is not supported by OS (Centos < 7) +- name: Fail if specified agent version is above maximum supported by OS fail: - msg: "Agent versions {{ agent_datadog_major }}.52 and above require Centos >= 7 or equivalent" - when: ansible_facts.os_family == "RedHat" and (ansible_facts.distribution_major_version | int) < 7 and (agent_datadog_minor | int) >= 52 + msg: "Agent versions {{ agent_datadog_major }}.{{ datadog_agent_max_version.minor + 1 }} and above not supported by current OS." + when: datadog_agent_max_version is defined and agent_datadog_minor | int > datadog_agent_max_version.minor - name: Set Agent default major version set_fact: From 1f13ef42401e5244f46f3d5a393ef7a8aafaa0c3 Mon Sep 17 00:00:00 2001 From: Alex Lopez Date: Thu, 7 Mar 2024 12:58:50 +0100 Subject: [PATCH 3/5] Use `rpm -E` for better detection of equivalent version --- tasks/os-check.yml | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/tasks/os-check.yml b/tasks/os-check.yml index 080eaae2..7547a423 100644 --- a/tasks/os-check.yml +++ b/tasks/os-check.yml @@ -5,8 +5,16 @@ when: ansible_facts.os_family not in ["RedHat", "Rocky", "AlmaLinux", "Debian", "Suse", "Windows", "Darwin"] - name: Upper bound last supported Agent version for Centos < 7 - set_fact: - datadog_agent_max_version: - full: "{{ datadog_agent_major_version | default('7', true) }}.51.1" - minor: 51 - when: ansible_facts.os_family == "RedHat" and (ansible_facts.distribution_major_version | int) < 7 + when: ansible_facts.os_family == "RedHat" + block: + - name: Get RHEL major version equivalent + command: "rpm -E %{rhel}" # noqa: command-instead-of-module + register: rhel_version + changed_when: false + check_mode: false + - name: Set upper agent version bound as ansible fact + set_fact: + datadog_agent_max_version: + full: "{{ datadog_agent_major_version | default('7', true) }}.51.1" + minor: 51 + when: rhel_version.stdout | int < 7 From 601f462cce855493fa50f157bdf0844b038650f5 Mon Sep 17 00:00:00 2001 From: Alex Lopez Date: Mon, 11 Mar 2024 11:36:38 +0100 Subject: [PATCH 4/5] Use an actual upper bound instead of a pinned patch version --- tasks/os-check.yml | 1 - tasks/pkg-redhat/install-latest.yml | 13 +++++++++++-- tasks/set-parse-version.yml | 7 +------ 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/tasks/os-check.yml b/tasks/os-check.yml index 7547a423..2770bd92 100644 --- a/tasks/os-check.yml +++ b/tasks/os-check.yml @@ -15,6 +15,5 @@ - name: Set upper agent version bound as ansible fact set_fact: datadog_agent_max_version: - full: "{{ datadog_agent_major_version | default('7', true) }}.51.1" minor: 51 when: rhel_version.stdout | int < 7 diff --git a/tasks/pkg-redhat/install-latest.yml b/tasks/pkg-redhat/install-latest.yml index 281d72d0..d95a9423 100644 --- a/tasks/pkg-redhat/install-latest.yml +++ b/tasks/pkg-redhat/install-latest.yml @@ -1,7 +1,16 @@ --- +- name: Set installation target for latest + set_fact: + # Apply a version cap if required, otherwise just target the agent package + datadog_agent_target: >- + {{ datadog_agent_flavor }} + {% if datadog_agent_max_version is defined %} + < 1:{{ agent_datadog_agent_major_version }}.{{ datadog_agent_max_version.minor + 1 }}.0-1 + {% endif %} + - name: Install latest datadog-agent package (dnf) dnf: - name: "{{ datadog_agent_flavor }}" + name: "{{ datadog_agent_target }}" update_cache: true state: latest # noqa package-latest register: agent_datadog_agent_install @@ -10,7 +19,7 @@ - name: Install latest datadog-agent package (yum) yum: - name: "{{ datadog_agent_flavor }}" + name: "{{ datadog_agent_target }}" update_cache: true state: latest # noqa package-latest register: agent_datadog_agent_install diff --git a/tasks/set-parse-version.yml b/tasks/set-parse-version.yml index d1353845..a897b51d 100644 --- a/tasks/set-parse-version.yml +++ b/tasks/set-parse-version.yml @@ -7,11 +7,6 @@ set_fact: agent_datadog_skip_install: false -- name: Apply upper bound for last supported Agent version when latest version is expected - set_fact: - datadog_agent_version: "{{ datadog_agent_max_version.full }}" - when: datadog_agent_max_version is defined and datadog_agent_version | length == 0 - - name: Include parse version tasks include_tasks: parse-version.yml when: datadog_agent_version | default('', true) | length > 0 @@ -19,7 +14,7 @@ - name: Fail if specified agent version is above maximum supported by OS fail: msg: "Agent versions {{ agent_datadog_major }}.{{ datadog_agent_max_version.minor + 1 }} and above not supported by current OS." - when: datadog_agent_max_version is defined and agent_datadog_minor | int > datadog_agent_max_version.minor + when: datadog_agent_max_version is defined and agent_datadog_minor is defined and agent_datadog_minor | int > datadog_agent_max_version.minor - name: Set Agent default major version set_fact: From e671e5546c1c0043390310e22b4f8307cea6ac9c Mon Sep 17 00:00:00 2001 From: Alex Lopez Date: Mon, 11 Mar 2024 11:49:22 +0100 Subject: [PATCH 5/5] Shuffle things around to make the changes more local to `pkg_redhat` --- tasks/os-check.yml | 14 -------------- tasks/pkg-redhat.yml | 18 ++++++++++++++++++ tasks/pkg-redhat/install-latest.yml | 4 ++-- tasks/set-parse-version.yml | 5 ----- 4 files changed, 20 insertions(+), 21 deletions(-) diff --git a/tasks/os-check.yml b/tasks/os-check.yml index 2770bd92..1ec5898c 100644 --- a/tasks/os-check.yml +++ b/tasks/os-check.yml @@ -3,17 +3,3 @@ fail: msg: "The Datadog Ansible role does not support your OS yet. Please email support@datadoghq.com to open a feature request." when: ansible_facts.os_family not in ["RedHat", "Rocky", "AlmaLinux", "Debian", "Suse", "Windows", "Darwin"] - -- name: Upper bound last supported Agent version for Centos < 7 - when: ansible_facts.os_family == "RedHat" - block: - - name: Get RHEL major version equivalent - command: "rpm -E %{rhel}" # noqa: command-instead-of-module - register: rhel_version - changed_when: false - check_mode: false - - name: Set upper agent version bound as ansible fact - set_fact: - datadog_agent_max_version: - minor: 51 - when: rhel_version.stdout | int < 7 diff --git a/tasks/pkg-redhat.yml b/tasks/pkg-redhat.yml index cc58df4c..765f346f 100644 --- a/tasks/pkg-redhat.yml +++ b/tasks/pkg-redhat.yml @@ -1,4 +1,22 @@ --- +- name: Set upper bound last supported Agent version for Centos < 7 + when: ansible_facts.os_family == "RedHat" + block: + - name: Get RHEL major version equivalent + command: "rpm -E %{rhel}" # noqa: command-instead-of-module + register: rhel_version + changed_when: false + check_mode: false + - name: Set upper agent version bound as ansible fact + set_fact: + datadog_agent_max_minor_version: 51 + when: rhel_version.stdout | int < 7 + +- name: Fail if specified agent version is above maximum supported by Centos < 7 and equivalent + fail: + msg: "Agent versions {{ agent_datadog_major }}.{{ datadog_agent_max_minor_version + 1 }} and above not supported by current OS (RHEL < 7 equivalent)." + when: datadog_agent_max_minor_version is defined and agent_datadog_minor is defined and agent_datadog_minor | int > datadog_agent_max_minor_version + - name: Fail early if Python 3 is used on CentOS / RHEL < 8 with old Ansible fail: msg: "The installation of the Agent on RedHat family systems using yum is not compatible with Python 3 with older Ansible versions. diff --git a/tasks/pkg-redhat/install-latest.yml b/tasks/pkg-redhat/install-latest.yml index d95a9423..94aad2ad 100644 --- a/tasks/pkg-redhat/install-latest.yml +++ b/tasks/pkg-redhat/install-latest.yml @@ -4,8 +4,8 @@ # Apply a version cap if required, otherwise just target the agent package datadog_agent_target: >- {{ datadog_agent_flavor }} - {% if datadog_agent_max_version is defined %} - < 1:{{ agent_datadog_agent_major_version }}.{{ datadog_agent_max_version.minor + 1 }}.0-1 + {% if datadog_agent_max_minor_version is defined %} + < 1:{{ agent_datadog_agent_major_version }}.{{ datadog_agent_max_minor_version + 1 }}.0-1 {% endif %} - name: Install latest datadog-agent package (dnf) diff --git a/tasks/set-parse-version.yml b/tasks/set-parse-version.yml index a897b51d..79ed10de 100644 --- a/tasks/set-parse-version.yml +++ b/tasks/set-parse-version.yml @@ -11,11 +11,6 @@ include_tasks: parse-version.yml when: datadog_agent_version | default('', true) | length > 0 -- name: Fail if specified agent version is above maximum supported by OS - fail: - msg: "Agent versions {{ agent_datadog_major }}.{{ datadog_agent_max_version.minor + 1 }} and above not supported by current OS." - when: datadog_agent_max_version is defined and agent_datadog_minor is defined and agent_datadog_minor | int > datadog_agent_max_version.minor - - name: Set Agent default major version set_fact: agent_datadog_agent_major_version: "7"