Skip to content

Commit

Permalink
Add default values when variables are defined but nil (#303)
Browse files Browse the repository at this point in the history
* Add default values when variables are defined but nil

* Fix typo
  • Loading branch information
KSerrania authored Nov 6, 2020
1 parent 0c7a077 commit 18a4013
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion tasks/agent-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

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

- name: Create Datadog agent config directory
Expand Down
6 changes: 3 additions & 3 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@

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

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

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

- name: Integrations Tasks
include_tasks: integration.yml
Expand Down
4 changes: 2 additions & 2 deletions tasks/pkg-windows-opts.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
- name: Set DD Username Arg
set_fact:
win_install_args: "{{ win_install_args }} DDAGENTUSER_NAME={{ datadog_windows_ddagentuser_name }}"
when: datadog_windows_ddagentuser_name | length > 0
when: datadog_windows_ddagentuser_name | default('', true) | length > 0

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

# check the registry. On upgrade, the location of the config file root will
# be set here.
Expand Down
4 changes: 2 additions & 2 deletions tasks/set-parse-version.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
- name: Convert datadog_agent_major_version to string
set_fact:
datadog_agent_major_version: "{{ datadog_agent_major_version | string }}"
datadog_agent_major_version: "{{ datadog_agent_major_version | default('', true) | string }}"

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

- name: Set Agent default major version
set_fact:
Expand Down
4 changes: 2 additions & 2 deletions tasks/win_agent_latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
- name: (Custom) Set agent download filename to latest
set_fact:
dd_download_url: "{{ datadog_windows_download_url }}"
when: datadog_windows_download_url | length > 0
when: datadog_windows_download_url | default('', true) | length > 0

- name: Set agent download filename to latest
set_fact:
dd_download_url: "{% if datadog_agent_major_version|int == 7 %}{{ datadog_windows_agent7_latest_url }}
{% else %}{{ datadog_windows_agent6_latest_url }}{% endif %}"
when: datadog_windows_download_url | length == 0
when: datadog_windows_download_url | default('', true) | length == 0
2 changes: 1 addition & 1 deletion templates/datadog.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ dd_url: {{ datadog_url }}
api_key: {{ datadog_api_key | default('youshouldsetthis') }}
{% endif %}

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

0 comments on commit 18a4013

Please sign in to comment.