From 314b32f1e5f2efd5abfd804b8e4c428947baa1fc Mon Sep 17 00:00:00 2001 From: Albert Vaca Cintora Date: Fri, 4 Dec 2020 14:25:01 +0100 Subject: [PATCH] Do not name the RPM repo file differently depending on the Agent version (#311) Use datadog.repo as the name, to be consistent with other install methods. --- tasks/pkg-redhat.yml | 59 +++++++++++++++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 14 deletions(-) diff --git a/tasks/pkg-redhat.yml b/tasks/pkg-redhat.yml index a902e099..b753cf3a 100644 --- a/tasks/pkg-redhat.yml +++ b/tasks/pkg-redhat.yml @@ -23,32 +23,63 @@ state: present when: not ansible_check_mode -- name: Install Datadog yum repo +- name: Install Datadog Agent 5 yum repo yum_repository: - name: "ansible_datadog_{{ item.key }}" + name: datadog description: Datadog, Inc. - baseurl: "{{ item.value }}" + baseurl: "{{ datadog_agent5_yum_repo }}" enabled: yes gpgcheck: yes - gpgkey: "{% if datadog_agent_major_version|int == 7 %}{{ datadog_yum_gpgkey_20200908 }}{% else %}{{ datadog_yum_gpgkey }}{% endif %}" - state: "{% if item.key == datadog_agent_major_version|int and datadog_yum_repo | length == 0 %}present{% else %}absent{% endif %}" - when: (not ansible_check_mode) - with_dict: - 5: '{{ datadog_agent5_yum_repo }}' - 6: '{{ datadog_agent6_yum_repo }}' - 7: '{{ datadog_agent7_yum_repo }}' - -- name: (Custom) Install Datadog yum repo + gpgkey: "{{ datadog_yum_gpgkey }}" + register: repofile5 + when: (datadog_agent_major_version|int == 5) and (datadog_yum_repo | length == 0) and (not ansible_check_mode) + +- name: Install Datadog Agent 6 yum repo yum_repository: - name: ansible_datadog_custom + name: datadog + description: Datadog, Inc. + baseurl: "{{ datadog_agent6_yum_repo }}" + enabled: yes + gpgcheck: yes + gpgkey: "{{ datadog_yum_gpgkey }}" + register: repofile6 + when: (datadog_agent_major_version|int == 6) and (datadog_yum_repo | length == 0) and (not ansible_check_mode) + +- name: Install Datadog Agent 7 yum repo + yum_repository: + name: datadog + description: Datadog, Inc. + baseurl: "{{ datadog_agent7_yum_repo }}" + enabled: yes + gpgcheck: yes + gpgkey: "{{ datadog_yum_gpgkey_20200908 }}" + register: repofile7 + when: (datadog_agent_major_version|int == 7) and (datadog_yum_repo | length == 0) and (not ansible_check_mode) + +- name: Install Datadog Custom yum repo + yum_repository: + name: datadog description: Datadog, Inc. baseurl: "{{ datadog_yum_repo }}" enabled: yes gpgcheck: yes gpgkey: "{{ datadog_yum_gpgkey }}" - state: present + register: repofilecustom when: (datadog_yum_repo | length > 0) and (not ansible_check_mode) +- name: Clean repo metadata if repo changed # noqa 503 + command: yum clean metadata --disablerepo="*" --enablerepo=datadog + ignore_errors: yes # Cleaning the metadata is only needed when downgrading a major version of the Agent, don't fail because of this + args: + warn: no + when: repofile5.changed or repofile6.changed or repofile7.changed or repofilecustom.changed + +- name: Remove old yum repo files + yum_repository: + name: "ansible_datadog_{{ item }}" + state: absent + with_items: [ 5, 6, 7, "custom" ] + - include_tasks: pkg-redhat/install-pinned.yml when: datadog_agent_redhat_version is defined