-
Notifications
You must be signed in to change notification settings - Fork 11
/
dt-oneagent-install-linux.yml
118 lines (118 loc) · 5.41 KB
/
dt-oneagent-install-linux.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# dynatrace oneagent install on linux
# hosts_group -> inventory group of hosts to execute playbook on
# dt_api_endpoint -> dynatrace environment api endpoint (include trailing /)
# dt_api_token -> dynatrace api install token
# dt_host_group -> dynatrace host group name
# dt_app_log_content_access -> flag to enable or disable log analytics on host (0 or 1)
# dt_infra_only -> flag to set cloud infrastructure monitoring mode on host (0 or 1)
---
-
hosts: "{{ hosts_group }}"
name: "dynatrace oneagent install on linux"
tasks:
# Check the OS architecture bitness
-
name: "check OS architecture"
debug:
var: ansible_architecture
when: ansible_architecture is defined
# Validate sudo access
-
name: "validate ansible execution on linux with sudo access"
shell:
cmd: ls /opt
become: yes
changed_when: False
# Check the latest available OneAgent version
-
name: "get latest oneagent version from dynatrace environment api"
local_action:
module: uri
url: "{{ dt_api_endpoint }}deployment/installer/agent/unix/default/latest/metainfo?flavor=default&arch=all&bitness=all"
headers:
accept: application/json
Authorization: Api-Token {{ dt_api_token }}
register: latest_version
-
name: "set oneagent latest version fact (dt_latest_version)"
set_fact:
dt_latest_version: "{{ latest_version.json.latestAgentVersion }}"
when: latest_version is defined
# Check if OneAgent is already installed, if yes then check installed version
-
name: "check if oneagent is already installed"
stat:
path: /opt/dynatrace/oneagent/agent/lib64/liboneagentos.so
register: installed
-
name: "check installed oneagent version"
shell: "/opt/dynatrace/oneagent/agent/tools/oneagentctl --version"
become: yes
register: current_version
when: installed.stat.exists == True
changed_when: False
-
name: "set oneagent current version fact (dt_current_version)"
set_fact:
dt_current_version: "{{lookup('flattened', current_version.stdout_lines)}}"
when: installed.stat.exists == True and current_version is defined
-
name: "debug output current version"
debug:
var: dt_current_version
when: installed.stat.exists == True and current_version is defined
-
name: "debug output latest version"
debug:
var: dt_latest_version
when: dt_latest_version is defined
# Download OneAgent install file if installation or upgrade is required
-
name: "download oneagent install file"
get_url:
# on the target systems, ensure that python is compiled with SSL support
# python -c "import ssl; print(ssl.OPENSSL_VERSION)"
#url: "{{ dt_api_endpoint }}deployment/installer/agent/unix/default/latest?Api-Token={{ dt_api_token }}&arch=x86&flavor=default" ## optionally pass Api-Token as a parameter instead of a header
url: "{{ dt_api_endpoint }}deployment/installer/agent/unix/default/latest?arch=x86&flavor=default" ## optionally pass Api-Token as a header instead of a parameter
headers: "Authorization: Api-Token {{ dt_api_token }} " ## optionally pass Api-Token as a header instead of a parameter
dest: /tmp/dynatrace-oneagent-linux-latest.sh
mode: '0777'
#validate_certs: false
when: installed.stat.exists != True or dt_current_version != dt_latest_version
changed_when: False
# Install OneAgent
-
name: "install: execute oneagent install file with root privileges"
shell: "sh /tmp/dynatrace-oneagent-linux-latest.sh HOST_GROUP={{ dt_host_group }} APP_LOG_CONTENT_ACCESS={{ dt_app_log_content_access }}{% if dt_infra_only is defined %} INFRA_ONLY={{ dt_infra_only }}{% endif %}"
become: yes
when: ansible_architecture != "armv7l" and installed.stat.exists == False
# Update OneAgent
-
name: "update: execute oneagent install file with root privileges"
shell: "sh /tmp/dynatrace-oneagent-linux-latest.sh HOST_GROUP={{ dt_host_group }} APP_LOG_CONTENT_ACCESS={{ dt_app_log_content_access }}{% if dt_infra_only is defined %} INFRA_ONLY={{ dt_infra_only }}{% endif %}"
become: yes
when: ansible_architecture != "armv7l" and installed.stat.exists == True and dt_current_version != dt_latest_version
# Validate OneAgent is installed
-
name: "validate oneagent installation"
stat:
path: /opt/dynatrace/oneagent/agent/lib64/liboneagentos.so
register: installed
failed_when: installed.stat.exists != True
# Check that the Host Group is correct, if not then correct it
-
name: "check host group is correct"
shell: "/opt/dynatrace/oneagent/agent/tools/oneagentctl --get-host-group"
become: yes
register: current_host_group
changed_when: False
-
name: "set current host group fact (dt_current_host_group)"
set_fact:
dt_current_host_group: "{{lookup('flattened', current_host_group.stdout_lines)}}"
when: current_host_group is defined
-
name: "update/correct host group setting if not correct"
shell: "service oneagent stop; /opt/dynatrace/oneagent/agent/tools/oneagentctl --set-host-group={{ dt_host_group }}; service oneagent start"
become: yes
when: dt_current_host_group != dt_host_group and dt_host_group is defined and dt_current_host_group is defined