From 6a558de6e6308bcb462b9ae4f2609315e13ca437 Mon Sep 17 00:00:00 2001 From: Naya1217 Date: Thu, 1 Aug 2024 18:41:42 -0400 Subject: [PATCH] Provide filename and line number of variable which triggered the deprecation warning (#83322) * Warning now shows line number and file in which the error occured Signed-off-by: Naya1217 --- changelogs/fragments/82528summary.yml | 3 +++ lib/ansible/playbook/base.py | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/82528summary.yml diff --git a/changelogs/fragments/82528summary.yml b/changelogs/fragments/82528summary.yml new file mode 100644 index 00000000000..ab99e13b6bd --- /dev/null +++ b/changelogs/fragments/82528summary.yml @@ -0,0 +1,3 @@ +bugfixes: +- Warning now includes filename and line number of variable + when specifying a list of dictionaries for vars (https://github.com/ansible/ansible/issues/82528). \ No newline at end of file diff --git a/lib/ansible/playbook/base.py b/lib/ansible/playbook/base.py index 96c3b9815dc..df18ecb61ad 100644 --- a/lib/ansible/playbook/base.py +++ b/lib/ansible/playbook/base.py @@ -589,10 +589,11 @@ class FieldAttributeBase: _validate_variable_keys(ds) return combine_vars(self.vars, ds) elif isinstance(ds, list): + line_file = getattr(ds, 'ansible_pos', ("unknown", 0)) display.deprecated( ( 'Specifying a list of dictionaries for vars is deprecated in favor of ' - 'specifying a dictionary.' + 'specifying a dictionary. Error occurred in the file: %s, line: %d' % (line_file[0], line_file[1]) ), version='2.18' )