-
Notifications
You must be signed in to change notification settings - Fork 224
/
Copy pathagent-win.yml
125 lines (112 loc) · 4.53 KB
/
agent-win.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
---
- name: Create main Datadog agent configuration file
win_template:
# FIXME: should have permissions set to only be readable by ddagentuser
src: datadog.yaml.j2
dest: "{{ agent_datadog_windows_config_root }}\\datadog.yaml"
when: datadog_manage_config
notify: restart datadog-agent-win
- name: Register all check configs present in datadog
win_find:
paths: "{{ ansible_facts.env['ProgramData'] }}\\Datadog\\conf.d"
patterns:
- "conf.yaml*"
recurse: true
depth: 2
file_type: file
register: agent_datadog_conf_paths
when: datadog_manage_config and (datadog_disable_untracked_checks or datadog_disable_default_checks)
- name: Delete checks not present in agent_datadog_tracked_checks
win_file:
path: "{{ ansible_facts.env['ProgramData'] }}\\Datadog\\conf.d\\{{ item }}.d\\conf.yaml"
state: absent
loop: >-
{{
agent_datadog_conf_paths.files | map(attribute='path') | select('match', '.*\\conf\.yaml$') | list
| map('win_dirname') | map('win_basename') | list | map('regex_replace', '^(.*).d$', '\1') | list
}}
when: datadog_manage_config and datadog_disable_untracked_checks and item not in agent_datadog_tracked_checks
notify: restart datadog-agent-win
- name: Delete default checks
win_file:
path: "{{ ansible_facts.env['ProgramData'] }}\\Datadog\\conf.d\\{{ item }}.d\\conf.yaml.default"
state: absent
loop: >-
{{
agent_datadog_conf_paths.files | map(attribute='path') | select('match', '.*\\conf\.yaml\.default$') | list
| map('win_dirname') | map('win_basename') | list | map('regex_replace', '^(.*).d$', '\1') | list
}}
when: datadog_manage_config and datadog_disable_default_checks and item not in agent_datadog_tracked_checks
notify: restart datadog-agent-win
- name: Delete example checks
win_file:
path: "{{ ansible_facts.env['ProgramData'] }}\\Datadog\\conf.d\\{{ item }}.d\\conf.yaml.example"
state: absent
loop: >-
{{
agent_datadog_conf_paths.files | map(attribute='path') | select('match', '.*\\conf\.yaml\.example$') | list
| map('win_dirname') | map('win_basename') | list | map('regex_replace', '^(.*).d$', '\1') | list
}}
when: datadog_manage_config and datadog_disable_example_checks and item not in agent_datadog_tracked_checks
notify: restart datadog-agent-win
- name: Ensure configuration directories are present for each Datadog check
win_file:
path: "{{ agent_datadog_windows_config_root }}\\conf.d\\{{ item }}.d"
state: directory
with_items: "{{ agent_datadog_checks | list }}"
when: datadog_manage_config
- name: Create a configuration file for each Datadog check
win_template:
src: checks.yaml.j2
dest: "{{ agent_datadog_windows_config_root }}\\conf.d\\{{ item }}.d\\conf.yaml"
with_items: "{{ agent_datadog_checks | list }}"
when: datadog_manage_config
notify: restart datadog-agent-win
- name: Remove old configuration file for each Datadog check
win_file:
path: "{{ agent_datadog_windows_config_root }}\\conf.d\\{{ item }}.yaml"
state: absent
with_items: "{{ agent_datadog_checks | list }}"
when: datadog_manage_config
notify: restart datadog-agent-win
- name: Create custom check file for each custom check
win_copy:
src: "{{ datadog_custom_checks[item] }}"
dest: "{{ agent_datadog_windows_config_root }}\\checks.d\\{{ item }}.py"
with_items: "{{ datadog_custom_checks | list }}"
notify: restart datadog-agent-win
- name: Ensure datadog-trace-agent and datadog-process-agent are not disabled
win_service:
name: "{{ item }}"
start_mode: manual
when: not datadog_skip_running_check and datadog_enabled and not ansible_check_mode
with_list:
- datadog-trace-agent
- datadog-process-agent
- name: Create system-probe configuration file
win_template:
src: system-probe.yaml.j2
dest: "{{ agent_datadog_windows_config_root }}\\system-probe.yaml"
when: datadog_manage_config
notify: restart datadog-agent-win
- name: Ensure datadog-agent is running
win_service:
name: datadogagent
state: started
start_mode: delayed
when: not datadog_skip_running_check and datadog_enabled and not ansible_check_mode
- name: Ensure datadog-agent is disabled
win_service:
name: "{{ item }}"
state: stopped
start_mode: disabled
when: not datadog_skip_running_check and not datadog_enabled
with_list:
- datadog-trace-agent
- datadog-process-agent
- datadogagent
- name: Create installation information file
template:
src: install_info.j2
dest: "{{ agent_datadog_windows_config_root }}\\install_info"
mode: "0644"