Skip to content

Commit 18a4013

Browse files
authored
Add default values when variables are defined but nil (#303)
* Add default values when variables are defined but nil * Fix typo
1 parent 0c7a077 commit 18a4013

File tree

6 files changed

+11
-11
lines changed

6 files changed

+11
-11
lines changed

tasks/agent-linux.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
- name: add "{{ datadog_user }}" user to additional groups
66
user: name="{{ datadog_user }}" groups="{{ datadog_additional_groups }}" append=yes
7-
when: datadog_additional_groups is defined and (datadog_additional_groups | length != 0)
7+
when: datadog_additional_groups | default([], true) | length > 0
88
notify: restart datadog-agent
99

1010
- name: Create Datadog agent config directory

tasks/main.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@
2424

2525
- name: Linux Configuration Tasks (Agent 5)
2626
include_tasks: agent5-linux.yml
27-
when: datadog_agent_major_version|int == 5 and ansible_os_family != "Windows"
27+
when: datadog_agent_major_version | int == 5 and ansible_os_family != "Windows"
2828

2929
- name: Linux Configuration Tasks
3030
include_tasks: agent-linux.yml
31-
when: datadog_agent_major_version|int > 5 and ansible_os_family != "Windows"
31+
when: datadog_agent_major_version | int > 5 and ansible_os_family != "Windows"
3232

3333
- name: Windows Configuration Tasks
3434
include_tasks: agent-win.yml
35-
when: datadog_agent_major_version|int > 5 and ansible_os_family == "Windows"
35+
when: datadog_agent_major_version | int > 5 and ansible_os_family == "Windows"
3636

3737
- name: Integrations Tasks
3838
include_tasks: integration.yml

tasks/pkg-windows-opts.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
- name: Set DD Username Arg
22
set_fact:
33
win_install_args: "{{ win_install_args }} DDAGENTUSER_NAME={{ datadog_windows_ddagentuser_name }}"
4-
when: datadog_windows_ddagentuser_name | length > 0
4+
when: datadog_windows_ddagentuser_name | default('', true) | length > 0
55

66
- name: Set DD Password Arg
77
set_fact:
88
win_install_args: "{{ win_install_args }} DDAGENTUSER_PASSWORD={{ datadog_windows_ddagentuser_password }}"
9-
when: datadog_windows_ddagentuser_password | length > 0
9+
when: datadog_windows_ddagentuser_password | default('', true) | length > 0
1010

1111
# check the registry. On upgrade, the location of the config file root will
1212
# be set here.

tasks/set-parse-version.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
22
- name: Convert datadog_agent_major_version to string
33
set_fact:
4-
datadog_agent_major_version: "{{ datadog_agent_major_version | string }}"
4+
datadog_agent_major_version: "{{ datadog_agent_major_version | default('', true) | string }}"
55

66
- include_tasks: parse-version.yml
7-
when: datadog_agent_version | length > 0
7+
when: datadog_agent_version | default('', true) | length > 0
88

99
- name: Set Agent default major version
1010
set_fact:

tasks/win_agent_latest.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
- name: (Custom) Set agent download filename to latest
44
set_fact:
55
dd_download_url: "{{ datadog_windows_download_url }}"
6-
when: datadog_windows_download_url | length > 0
6+
when: datadog_windows_download_url | default('', true) | length > 0
77

88
- name: Set agent download filename to latest
99
set_fact:
1010
dd_download_url: "{% if datadog_agent_major_version|int == 7 %}{{ datadog_windows_agent7_latest_url }}
1111
{% else %}{{ datadog_windows_agent6_latest_url }}{% endif %}"
12-
when: datadog_windows_download_url | length == 0
12+
when: datadog_windows_download_url | default('', true) | length == 0

templates/datadog.yaml.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ dd_url: {{ datadog_url }}
1414
api_key: {{ datadog_api_key | default('youshouldsetthis') }}
1515
{% endif %}
1616

17-
{% if datadog_config is defined and datadog_config|length > 0 -%}
17+
{% if datadog_config | default({}, true) | length > 0 -%}
1818
{{ datadog_config | to_nice_yaml }}
1919
{% endif %}

0 commit comments

Comments
 (0)