Skip to content

Commit 45a083c

Browse files
authored
Add datadog_manage_config to disable changing the Agent config files (#410)
Adds a new variable datadog_manage_config that defaults to true but can be set to false. Doing so will make our role not change any of the Agent config files when it runs. This allows using the role to update the Agent if manual modifications have been made to the config files without overwriting them.
1 parent 8f932e4 commit 45a083c

File tree

5 files changed

+71
-16
lines changed

5 files changed

+71
-16
lines changed

.circleci/config.yml

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ commands:
3131
- run: ansible-playbook -i ./ci_test/inventory/ci.ini "./ci_test/install_agent_<<parameters.version>>.yaml" -e 'ansible_python_interpreter=/usr/bin/<<parameters.python>>'
3232
- run: datadog-agent version
3333

34+
test_install_no_manage_config:
35+
parameters:
36+
version:
37+
type: string
38+
python:
39+
type: string
40+
steps:
41+
- run: ansible-playbook -i ./ci_test/inventory/ci.ini "./ci_test/install_agent_<<parameters.version>>.yaml" -e '{"ansible_python_interpreter":"/usr/bin/<<parameters.python>>","datadog_manage_config":false}'
42+
- run: bash -c '[ -f /etc/datadog-agent/datadog.yaml.example ] || [ -f /etc/dd-agent/datadog.conf.example ]'
43+
- run: bash -c '[ ! -f /etc/datadog-agent/datadog.yaml ] && [ ! -f /etc/datadog-agent/system-probe.yaml ] && [ ! -f /etc/datadog-agent/security-agent.yaml ] && [ ! -f /etc/dd-agent/datadog.conf ]'
44+
3445
downgrade_agent_5_23_0:
3546
parameters:
3647
python:
@@ -121,6 +132,24 @@ jobs:
121132
version: "<<parameters.agent_version>>"
122133
python: "<<parameters.python>>"
123134

135+
test_install_no_manage_config:
136+
parameters:
137+
ansible_version:
138+
type: string
139+
agent_version:
140+
type: string
141+
os:
142+
type: string
143+
python:
144+
type: string
145+
docker:
146+
- image: datadog/docker-library:ansible_<<parameters.os>>_<<parameters.ansible_version>>
147+
steps:
148+
- checkout
149+
- test_install_no_manage_config:
150+
version: "<<parameters.agent_version>>"
151+
python: "<<parameters.python>>"
152+
124153
workflows:
125154
version: 2
126155
test_datadog_role:
@@ -142,7 +171,16 @@ workflows:
142171
agent_version: ["5", "6", "7"]
143172
os: ["debian"]
144173
python: ["python3"]
145-
174+
175+
# Newer debian images only have Pythpn 3 installed
176+
- test_install_no_manage_config:
177+
matrix:
178+
parameters:
179+
ansible_version: ["2_10"]
180+
agent_version: ["5", "7"]
181+
os: ["debian"]
182+
python: ["python3"]
183+
146184
# centos = CentOS 7. CentOS <= 7 + Python3 is not supported,
147185
# as the yum module is Python2-only.
148186
- test_install_downgrade:

defaults/main.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
---
22
role_version: 4.12.0
33

4-
# default system-probe.yaml options
5-
system_probe_config: {}
6-
7-
network_config: {}
8-
94
# define if the datadog-agent services should be enabled
105
datadog_enabled: yes
116

7+
# Whether the datadog.conf / datadog.yaml, system-probe.yaml, security-agent.yaml and checks config under conf.d are managed by Ansible
8+
datadog_manage_config: yes
9+
1210
# default datadog.conf / datadog.yaml options
1311
datadog_config: {}
1412

13+
# default system-probe.yaml options
14+
system_probe_config: {}
15+
network_config: {}
16+
1517
# default checks enabled
1618
datadog_checks: {}
1719

tasks/agent-linux.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
dest: /etc/datadog-agent
2424
state: directory
2525
mode: 0755
26+
when: datadog_manage_config
2627

2728
- name: Create main Datadog agent configuration file
2829
template:
@@ -31,6 +32,7 @@
3132
mode: 0640
3233
owner: "{{ datadog_user }}"
3334
group: "{{ datadog_group }}"
35+
when: datadog_manage_config
3436
notify: restart datadog-agent
3537

3638
- name: Register all checks directories present in datadog
@@ -40,22 +42,22 @@
4042
- "*.d"
4143
file_type: directory
4244
register: datadog_conf_directories
43-
when: datadog_disable_untracked_checks or datadog_disable_default_checks
45+
when: datadog_manage_config and (datadog_disable_untracked_checks or datadog_disable_default_checks)
4446

4547
- name: Delete checks not present in datadog_tracked_checks
4648
file:
4749
path: "/etc/datadog-agent/conf.d/{{ item }}.d/conf.yaml"
4850
state: absent
4951
loop: "{{ datadog_conf_directories.files | map(attribute='path') | list | map('basename') | list | map('regex_replace', '^(.*).d$', '\\1') | list }}"
50-
when: datadog_disable_untracked_checks and item not in datadog_tracked_checks
52+
when: datadog_manage_config and datadog_disable_untracked_checks and item not in datadog_tracked_checks
5153
notify: restart datadog-agent
5254

5355
- name: Delete all default checks
5456
file:
5557
path: "/etc/datadog-agent/conf.d/{{ item }}.d/conf.yaml.default"
5658
state: absent
5759
loop: "{{ datadog_conf_directories.files | map(attribute='path') | list | map('basename') | list | map('regex_replace', '^(.*).d$', '\\1') | list }}"
58-
when: datadog_disable_default_checks and item not in datadog_tracked_checks
60+
when: datadog_manage_config and datadog_disable_default_checks and item not in datadog_tracked_checks
5961
notify: restart datadog-agent
6062

6163
- name: Ensure configuration directories are present for each Datadog check
@@ -66,6 +68,7 @@
6668
group: "{{ datadog_group }}"
6769
mode: 0755
6870
with_items: '{{ datadog_checks|list }}'
71+
when: datadog_manage_config
6972

7073
- name: Create a configuration file for each Datadog check
7174
template:
@@ -75,13 +78,15 @@
7578
owner: "{{ datadog_user }}"
7679
group: "{{ datadog_group }}"
7780
with_items: "{{ datadog_checks|list }}"
81+
when: datadog_manage_config
7882
notify: restart datadog-agent
7983

8084
- name: Remove old configuration file for each Datadog check
8185
file:
8286
dest: "/etc/datadog-agent/conf.d/{{ item }}.yaml"
8387
state: absent
8488
with_items: "{{ datadog_checks|list }}"
89+
when: datadog_manage_config
8590
notify: restart datadog-agent
8691

8792
- name: Create system-probe configuration file
@@ -91,6 +96,7 @@
9196
mode: 0640
9297
owner: "root"
9398
group: "{{ datadog_group }}"
99+
when: datadog_manage_config
94100
notify:
95101
"{% if datadog_before_7180 %}restart datadog-agent-sysprobe{% else %}restart datadog-agent{% endif %}"
96102

@@ -179,6 +185,7 @@
179185
mode: 0640
180186
owner: "root"
181187
group: "{{ datadog_group }}"
188+
when: datadog_manage_config
182189
notify:
183190
"{% if datadog_before_7180 %}restart datadog-agent-sysprobe{% else %}restart datadog-agent{% endif %}"
184191

tasks/agent-win.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#FIXME: should have permissions set to only be readable by ddagentuser
55
src: datadog.yaml.j2
66
dest: "{{ datadog_windows_config_root }}\\datadog.yaml"
7+
when: datadog_manage_config
78
notify: restart datadog-agent-win
89

910
- name: Register all checks directories present in datadog
@@ -13,42 +14,45 @@
1314
- "*.d"
1415
file_type: directory
1516
register: datadog_conf_directories
16-
when: datadog_disable_untracked_checks or datadog_disable_default_checks
17+
when: datadog_manage_config and (datadog_disable_untracked_checks or datadog_disable_default_checks)
1718

1819
- name: Delete checks not present in datadog_tracked_checks
1920
win_file:
2021
path: "{{ ansible_facts.env['ProgramData'] }}\\Datadog\\conf.d\\{{ item }}.d\\conf.yaml"
2122
state: absent
2223
loop: "{{ datadog_conf_directories.files | map(attribute='path') | list | map('win_basename') | list | map('regex_replace', '^(.*).d$', '\\1') | list }}"
23-
when: datadog_disable_untracked_checks and item not in datadog_tracked_checks
24+
when: datadog_manage_config and datadog_disable_untracked_checks and item not in datadog_tracked_checks
2425
notify: restart datadog-agent-win
2526

2627
- name: Delete default checks
2728
win_file:
2829
path: "{{ ansible_facts.env['ProgramData'] }}\\Datadog\\conf.d\\{{ item }}.d\\conf.yaml.default"
2930
state: absent
3031
loop: "{{ datadog_conf_directories.files | map(attribute='path') | list | map('win_basename') | list | map('regex_replace', '^(.*).d$', '\\1') | list }}"
31-
when: datadog_disable_default_checks and item not in datadog_tracked_checks
32+
when: datadog_manage_config and datadog_disable_default_checks and item not in datadog_tracked_checks
3233
notify: restart datadog-agent-win
3334

3435
- name: Ensure configuration directories are present for each Datadog check
3536
win_file:
3637
path: "{{ datadog_windows_config_root }}\\conf.d\\{{ item }}.d"
3738
state: directory
3839
with_items: '{{ datadog_checks|list }}'
40+
when: datadog_manage_config
3941

4042
- name: Create a configuration file for each Datadog check
4143
win_template:
4244
src: checks.yaml.j2
4345
dest: "{{ datadog_windows_config_root }}\\conf.d\\{{ item }}.d\\conf.yaml"
4446
with_items: "{{ datadog_checks|list }}"
47+
when: datadog_manage_config
4548
notify: restart datadog-agent-win
4649

4750
- name: Remove old configuration file for each Datadog check
4851
win_file:
4952
path: "{{ datadog_windows_config_root }}\\conf.d\\{{ item }}.yaml"
5053
state: absent
5154
with_items: "{{ datadog_checks|list }}"
55+
when: datadog_manage_config
5256
notify: restart datadog-agent-win
5357

5458
- name: Ensure datadog-trace-agent and datadog-process-agent are not disabled
@@ -64,6 +68,7 @@
6468
win_template:
6569
src: system-probe.yaml.j2
6670
dest: "{{ datadog_windows_config_root }}\\system-probe.yaml"
71+
when: datadog_manage_config
6772
notify: restart datadog-agent-win
6873

6974
- name: Ensure datadog-agent is running

tasks/agent5-linux.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
dest: /etc/dd-agent
55
state: directory
66
mode: 0755
7+
when: datadog_manage_config
78

89
- name: (agent5) Create main Datadog agent configuration file
910
template:
@@ -12,6 +13,7 @@
1213
owner: "{{ datadog_user }}"
1314
group: "{{ datadog_group }}"
1415
mode: 0644 #FIXME: should have permissions set to only be readable by owner
16+
when: datadog_manage_config
1517
notify: restart datadog-agent
1618

1719
- name: (agent5) Ensure datadog-agent is running
@@ -35,7 +37,7 @@
3537
- "*.yaml"
3638
file_type: file
3739
register: datadog_conf_files
38-
when: datadog_disable_untracked_checks
40+
when: datadog_manage_config and datadog_disable_untracked_checks
3941

4042
- name: Register all checks files present in datadog
4143
find:
@@ -44,14 +46,14 @@
4446
- "*.yaml.default"
4547
file_type: file
4648
register: datadog_conf_files_default
47-
when: datadog_disable_default_checks
49+
when: datadog_manage_config and datadog_disable_default_checks
4850

4951
- name: Delete checks not present in datadog_tracked_checks
5052
file:
5153
path: "/etc/dd-agent/conf.d/{{ item }}.yaml"
5254
state: absent
5355
loop: "{{ datadog_conf_files.files | map(attribute='path') | list | map('basename') | list | map('regex_replace', '^(.*).yaml$', '\\1') | list }}"
54-
when: datadog_disable_untracked_checks and item not in datadog_tracked_checks
56+
when: datadog_manage_config and datadog_disable_untracked_checks and item not in datadog_tracked_checks
5557
notify: restart datadog-agent
5658

5759
- name: Delete default checks
@@ -60,7 +62,7 @@
6062
state: absent
6163
loop: "{{ datadog_conf_files_default.files | map(attribute='path') | list
6264
| map('basename') | list | map('regex_replace', '^(.*).yaml.default$', '\\1') | list }}"
63-
when: datadog_disable_default_checks and item not in datadog_tracked_checks
65+
when: datadog_manage_config and datadog_disable_default_checks and item not in datadog_tracked_checks
6466
notify: restart datadog-agent
6567

6668
- name: (agent5) Create a configuration file for each Datadog check
@@ -71,4 +73,5 @@
7173
group: "{{ datadog_group }}"
7274
mode: 0644 #FIXME: should have permissions set to only be readable by owner
7375
with_items: "{{ datadog_checks|list }}"
76+
when: datadog_manage_config
7477
notify: restart datadog-agent

0 commit comments

Comments
 (0)