-
Notifications
You must be signed in to change notification settings - Fork 222
/
parse-version.yml
104 lines (89 loc) · 5.4 KB
/
parse-version.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
---
- name: Parse Agent version
set_fact:
agent_version: "{{ datadog_agent_version
| regex_search(agent_regexp, '\\g<epoch>', '\\g<major>', '\\g<minor>', '\\g<bugfix>', '\\g<suffix>', '\\g<release>') }}"
vars:
agent_regexp: (?:(?P<epoch>[0-9]+):)?(?P<major>[0-9]+)\.(?P<minor>[0-9]+)\.(?P<bugfix>[0-9]+)(?P<suffix>(?:~|-)[^0-9\s-]+[^-\s]*)?(?:-(?P<release>[0-9]+))?
- name: Set version vars
set_fact:
agent_datadog_epoch: "{{ agent_version.0 | default('', true) | string }}"
agent_datadog_major: "{{ agent_version.1 | default('', true) | string }}"
agent_datadog_minor: "{{ agent_version.2 | default('', true) | string }}"
agent_datadog_bugfix: "{{ agent_version.3 | default('', true) | string }}"
agent_datadog_suffix: "{{ agent_version.4 | default('', true) | string }}"
agent_datadog_release: "{{ agent_version.5 | default('', true) | string }}"
- name: Fill empty version epoch with default
set_fact:
agent_datadog_epoch: "1"
when: agent_datadog_epoch | length == 0
- name: Fill empty version release with default
set_fact:
agent_datadog_release: "1"
when: agent_datadog_release | length == 0
- name: Stop play if datadog_agent_version and datadog_agent_major_version are not compatible
fail:
msg: "The provided major version {{ agent_datadog_agent_major_version }} is not compatible with the version {{ agent_datadog_major }}
deduced from datadog_agent_version ({{ datadog_agent_version }}). Aborting play."
when: agent_datadog_agent_major_version | length > 0 and agent_datadog_major != agent_datadog_agent_major_version
- name: Set agent_datadog_agent_major_version to deduced value from datadog_agent_version
set_fact:
agent_datadog_agent_major_version: "{{ agent_datadog_major }}"
- name: Set helper variables
set_fact:
agent_datadog_agent_linux_version: "{{ agent_datadog_epoch }}:{{ agent_datadog_major }}.{{ agent_datadog_minor }}.{{ agent_datadog_bugfix }}{{ agent_datadog_suffix }}-{{ agent_datadog_release }}" # noqa yaml[line-length]
agent_datadog_rpm_version_finding_cmd: "rpm -q --qf '%{EPOCH}:%{VERSION}-%{RELEASE}' {{ datadog_agent_flavor }}"
- name: Set OS-specific versions
# NOTE: if changing these, make sure the format correspond with values in agent_datadog_version_finding_cmds below
set_fact:
agent_datadog_agent_debian_version: "{{ agent_datadog_agent_linux_version }}"
agent_datadog_agent_redhat_version: "{{ agent_datadog_agent_linux_version }}"
agent_datadog_agent_suse_version: "{{ agent_datadog_agent_linux_version }}"
agent_datadog_agent_windows_version: "{{ agent_datadog_major }}.{{ agent_datadog_minor }}.{{ agent_datadog_bugfix }}{{ agent_datadog_suffix }}"
agent_datadog_agent_macos_version: "{{ agent_datadog_major }}.{{ agent_datadog_minor }}.{{ agent_datadog_bugfix }}{{ agent_datadog_suffix }}"
- name: Construct commands to find Agent version
set_fact:
agent_datadog_version_finding_cmds:
Debian: "dpkg-query --showformat '${Status} ${Version}\n' --show {{ datadog_agent_flavor }} | grep installed | awk '{print $NF}'"
RedHat: "{{ agent_datadog_rpm_version_finding_cmd }}"
Rocky: "{{ agent_datadog_rpm_version_finding_cmd }}"
AlmaLinux: "{{ agent_datadog_rpm_version_finding_cmd }}"
Suse: "{{ agent_datadog_rpm_version_finding_cmd }}"
- name: Create OS-specific version dict
set_fact:
agent_datadog_agent_os2version:
Debian: "{{ agent_datadog_agent_debian_version }}"
RedHat: "{{ agent_datadog_agent_redhat_version }}"
Rocky: "{{ agent_datadog_agent_redhat_version }}"
AlmaLinux: "{{ agent_datadog_agent_redhat_version }}"
Suse: "{{ agent_datadog_agent_suse_version }}"
Windows: "{{ agent_datadog_agent_windows_version }}"
Darwin: "{{ agent_datadog_agent_macos_version }}"
- name: Get Linux Agent version
shell: "{{ agent_datadog_version_finding_cmds[ansible_facts.os_family] }}" # noqa command-instead-of-shell - We need shell because of pipes
register: agent_datadog_version_check_linux
changed_when: false
failed_when: false
check_mode: false
when: ansible_facts.system is defined and ansible_facts.system == "Linux"
# The task is win_shell, so if users don't have the "ansible.windows" collection installed,
# parsing the task would fail even if the host is not Windows. By hiding the task inside
# a conditionally included file, we can prevent this.
- name: Include Windows Agent version tasks
include_tasks: parse-version-windows.yml
when: ansible_facts.os_family == "Windows"
- name: Include macOS Agent version tasks
include_tasks: parse-version-macos.yml
when: ansible_facts.os_family == "Darwin"
- name: Set skip install flag if version already installed (Linux)
set_fact:
agent_datadog_skip_install: "{{ agent_datadog_version_check_linux.stdout | trim == agent_datadog_agent_os2version[ansible_facts.os_family] }}"
when: ansible_facts.system is defined and ansible_facts.system == "Linux"
- name: Set skip install flag if version already installed (Windows)
set_fact:
agent_datadog_skip_install: "{{ agent_datadog_version_check_win.stdout | trim == agent_datadog_agent_os2version[ansible_facts.os_family] }}"
when: ansible_facts.os_family == "Windows"
- name: Set skip install flag if version already installed (macOS)
set_fact:
agent_datadog_skip_install: "{{ agent_datadog_version_check_macos.stdout | trim == agent_datadog_agent_os2version[ansible_facts.os_family] }}"
when: ansible_facts.os_family == "Darwin"