Skip to content

Conversation

@KSerrania
Copy link
Contributor

What does this PR do?

Adds guards when trying to read variable lengths, to avoid reading the length of null, which results in a crash.

Motivation

It is possible to get into situations where a variable is set, but has a null value (eg. by adding key: in the yaml vars). If we check the length of such a variable (which should thus be a list, string or dictionary), we should first default to a reasonable value if a null value is given.

default needs to be used with boolean=True to also match falsey values (such as null), otherwise it only matches undefined variables.

@KSerrania KSerrania requested a review from a team as a code owner October 1, 2020 19:43
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's two consecutive | on this line, is that on purpose ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a typo indeed 😄

Copy link
Contributor

@julien-lebot julien-lebot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with Ansible but those changes LGTM !

@derekwbrown derekwbrown merged commit 18a4013 into master Nov 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants