mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 21:32:49 +00:00
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:
committed by
Martin Krizek
parent
fecffea370
commit
21cd24a0dd
@@ -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
|
||||
|
||||
18
test/integration/targets/conditionals/test_no_warnings.yml
Normal file
18
test/integration/targets/conditionals/test_no_warnings.yml
Normal 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
|
||||
14
test/integration/targets/conditionals/test_warnings.yml
Normal file
14
test/integration/targets/conditionals/test_warnings.yml
Normal 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
|
||||
Reference in New Issue
Block a user