-
Notifications
You must be signed in to change notification settings - Fork 1
/
acmTutorial.playbook.yml
232 lines (218 loc) · 7.01 KB
/
acmTutorial.playbook.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
---
- name: ACM Tutorial Playbook
hosts: apache
vars:
hostList: "{{ lookup('file', 'hostList.json') }}"
tenant_id: "***"
api_token: "***"
oneagent_installer_script_url: "https://{{ tenant_id }}.live.dynatrace.com/api/v1/deployment/installer/agent/unix/default/latest?Api-Token=***&arch=x86&flavor=default"
defaultHostGroup: "DefaultGroup"
tasks:
- name: Check if Dynatrace OneAgent is already installed
stat:
path: /opt/dynatrace/oneagent/agent/lib64/liboneagentos.so
register: agent_installed
- name: Set Host Group Facts
set_fact:
hostGroup: "{{ item.hostGroup }}"
loop: "{{ hostList }}"
when: item.hostname == inventory_hostname
- name: Download OneAgent
get_url:
url: "{{ oneagent_installer_script_url }}"
dest: "/tmp/dynatrace-oneagent.sh"
when: agent_installed.stat.exists == False
- name: Install Agent
shell: "sh /tmp/dynatrace-oneagent.sh --set-app-log-content-access=true --set-host-group={{ hostvars[inventory_hostname].hostGroup | default(defaultHostGroup) }}"
become: yes
when: agent_installed.stat.exists == False
- name: Get Current Host Group
shell: "/opt/dynatrace/oneagent/agent/tools/lib64/oneagentutil --get-host-group"
become: yes
when: agent_installed.stat.exists == True
register: currentHostGroup
- name: Update Host Group
shell: "/opt/dynatrace/oneagent/agent/tools/lib64/oneagentutil --set-host-group {{ hostvars[inventory_hostname].hostGroup | default(defaultHostGroup) }} --restart-service"
become: yes
when: agent_installed.stat.exists == True and currentHostGroup.stdout != (hostvars[inventory_hostname].hostGroup | default(defaultHostGroup))
- name: "Set Facts"
set_fact:
"metadata" : "{{ item.metadata }}"
loop: "{{ hostList }}"
when: item.hostname == inventory_hostname
- name: "Remove File if it Exists"
become: yes
file:
path: /var/lib/dynatrace/oneagent/agent/config/hostcustomproperties.conf
state: absent
- name: "Write KVs to File"
become: yes
lineinfile:
path: /var/lib/dynatrace/oneagent/agent/config/hostcustomproperties.conf
line: "{{ item.key }}={{ item.value }}"
create: yes
with_dict: "{{ hostvars[inventory_hostname]['metadata'] }}"
- name: Create ChargeCode Auto Tag Rule
run_once: true
uri:
method: PUT
status_code: 201, 204
body_format: json
url: https://{{ tenant_id }}.live.dynatrace.com/api/config/v1/autoTags/12345678-1234-1234-1234-123456789012?Api-Token={{ api_token }}
body: |
{
"name": "ChargeCode",
"rules": [
{
"type": "PROCESS_GROUP",
"enabled": true,
"valueFormat": "{Host:Environment:ChargeCode}",
"propagationTypes": [
"PROCESS_GROUP_TO_HOST",
"PROCESS_GROUP_TO_SERVICE"
],
"conditions": [
{
"key": {
"attribute": "HOST_CUSTOM_METADATA",
"dynamicKey": {
"source": "ENVIRONMENT",
"key": "ChargeCode"
},
"type": "HOST_CUSTOM_METADATA_KEY"
},
"comparisonInfo": {
"type": "STRING",
"operator": "EXISTS",
"value": null,
"negate": false,
"caseSensitive": null
}
}
]
}
]
}
- name: Create ConsumingRegion Auto Tag Rule
run_once: true
uri:
method: PUT
status_code: 201, 204
body_format: json
url: https://{{ tenant_id }}.live.dynatrace.com/api/config/v1/autoTags/23456789-2345-2345-2345-234567890123?Api-Token={{ api_token }}
body: |
{
"name": "ConsumingRegion",
"rules": [
{
"type": "PROCESS_GROUP",
"enabled": true,
"valueFormat": "{Host:Environment:ConsumingRegion}",
"propagationTypes": [
"PROCESS_GROUP_TO_HOST",
"PROCESS_GROUP_TO_SERVICE"
],
"conditions": [
{
"key": {
"attribute": "HOST_CUSTOM_METADATA",
"dynamicKey": {
"source": "ENVIRONMENT",
"key": "ConsumingRegion"
},
"type": "HOST_CUSTOM_METADATA_KEY"
},
"comparisonInfo": {
"type": "STRING",
"operator": "EXISTS",
"value": null,
"negate": false,
"caseSensitive": null
}
}
]
}
]
}
- name: Create Location Auto Tag Rule
run_once: true
uri:
method: PUT
status_code: 201, 204
body_format: json
url: https://{{ tenant_id }}.live.dynatrace.com/api/config/v1/autoTags/34567890-3456-3456-3456-345678901234?Api-Token={{ api_token }}
body: |
{
"name": "Location",
"rules": [
{
"type": "PROCESS_GROUP",
"enabled": true,
"valueFormat": "{Host:Environment:Location}",
"propagationTypes": [
"PROCESS_GROUP_TO_HOST",
"PROCESS_GROUP_TO_SERVICE"
],
"conditions": [
{
"key": {
"attribute": "HOST_CUSTOM_METADATA",
"dynamicKey": {
"source": "ENVIRONMENT",
"key": "Location"
},
"type": "HOST_CUSTOM_METADATA_KEY"
},
"comparisonInfo": {
"type": "STRING",
"operator": "EXISTS",
"value": null,
"negate": false,
"caseSensitive": null
}
}
]
}
]
}
- name: Create Owner Auto Tag Rule
run_once: true
uri:
method: PUT
status_code: 201, 204
body_format: json
url: https://{{ tenant_id }}.live.dynatrace.com/api/config/v1/autoTags/45678901-4567-4567-4567-456789012345?Api-Token={{ api_token }}
body: |
{
"name": "Owner",
"rules": [
{
"type": "PROCESS_GROUP",
"enabled": true,
"valueFormat": "{Host:Environment:Owner}",
"propagationTypes": [
"PROCESS_GROUP_TO_HOST",
"PROCESS_GROUP_TO_SERVICE"
],
"conditions": [
{
"key": {
"attribute": "HOST_CUSTOM_METADATA",
"dynamicKey": {
"source": "ENVIRONMENT",
"key": "Owner"
},
"type": "HOST_CUSTOM_METADATA_KEY"
},
"comparisonInfo": {
"type": "STRING",
"operator": "EXISTS",
"value": null,
"negate": false,
"caseSensitive": null
}
}
]
}
]
}