improve conditional warnings (#57190)

* Fix order for warning on templated conditionals

Fix bare variable warnings when the variable is a boolean

* changelog

* Add tests for cases that should and should not give warnings

If the behavior may change when the default behavior for CONDITIONAL_BARE_VARS becomes False there should be a warning. Boolean type conditionals will not change in behavior so don't warn.

* oops, forgot to add files

* typo
This commit is contained in:
Sloane Hertel
2019-06-03 06:12:33 -04:00
committed by Martin Krizek
parent fecffea370
commit 21cd24a0dd
5 changed files with 54 additions and 6 deletions

View File

@@ -4,3 +4,12 @@ set -eux
ANSIBLE_CONDITIONAL_BARE_VARS=1 ansible-playbook -i ../../inventory play.yml "$@"
ANSIBLE_CONDITIONAL_BARE_VARS=0 ansible-playbook -i ../../inventory play.yml "$@"
export ANSIBLE_CONDITIONAL_BARE_VARS=1
export ANSIBLE_DEPRECATION_WARNINGS=True
# No warnings for conditionals that are already type bool
test "$(ansible-playbook -i ../../inventory test_no_warnings.yml "$@" 2>&1 | grep -c '\[DEPRECATION WARNING\]')" = 0
# Warn for bare vars of other types since they may be interpreted differently when CONDITIONAL_BARE_VARS defaults to False
test "$(ansible-playbook -i ../../inventory test_warnings.yml "$@" 2>&1 | grep -c '\[DEPRECATION WARNING\]')" = 2

View File

@@ -0,0 +1,18 @@
- hosts: testhost
gather_facts: false
vars:
boolean_var: false
nested:
bool_var: false
tasks:
- name: Run tasks with previous warnings requesting the bool filter on type boolean vars
block:
- debug:
when: boolean_var
- debug:
when: nested.bool_var
- debug:
when: double_interpolated
vars:
double_interpolated: "{{ other }}"
other: false

View File

@@ -0,0 +1,14 @@
- hosts: testhost
gather_facts: false
vars:
str_boolean_var: 'false'
tasks:
- name: Run tasks with warnings for conditionals that will change in behavior depending on CONDITIONAL_BARE_VARS
block:
- debug:
when: str_boolean_var
- debug:
when: double_interpolated
vars:
double_interpolated: other
other: false