From a37df1a94a0f26de3323f0f9824900c19c5f1dbd Mon Sep 17 00:00:00 2001 From: Matt Davis <6775756+nitzmahone@users.noreply.github.com> Date: Thu, 26 Jun 2025 11:34:29 -0700 Subject: [PATCH] Remove redundant vars FA on PlaybookInclude (#85395) * The redundant FA declaration was not static, which broke a number of automatic validation behaviors. * Added tests to assert deferred validation and lack of templating on `import_playbook.vars`. Co-authored-by: Matt Clay (cherry picked from commit 73369f53af2fadad75632b3ce62bbd5f02f8ca27) --- lib/ansible/playbook/playbook_include.py | 1 - .../include_import/playbook/playbook_using_a_var.yml | 6 ++++++ .../include_import/playbook/test_import_playbook.yml | 12 ++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 test/integration/targets/include_import/playbook/playbook_using_a_var.yml diff --git a/lib/ansible/playbook/playbook_include.py b/lib/ansible/playbook/playbook_include.py index dfa0971263b..4ec9090de65 100644 --- a/lib/ansible/playbook/playbook_include.py +++ b/lib/ansible/playbook/playbook_include.py @@ -34,7 +34,6 @@ from ansible import constants as C class PlaybookInclude(Base, Conditional, Taggable): import_playbook = NonInheritableFieldAttribute(isa='string', required=True) - vars_val = NonInheritableFieldAttribute(isa='dict', default=dict, alias='vars') _post_validate_object = True # manually post_validate to get free arg validation/coercion diff --git a/test/integration/targets/include_import/playbook/playbook_using_a_var.yml b/test/integration/targets/include_import/playbook/playbook_using_a_var.yml new file mode 100644 index 00000000000..01745aeb2a8 --- /dev/null +++ b/test/integration/targets/include_import/playbook/playbook_using_a_var.yml @@ -0,0 +1,6 @@ +- hosts: localhost + gather_facts: no + tasks: + - name: Verify an imported playbook can see a var it was given + assert: + that: pb_var == 'hello' diff --git a/test/integration/targets/include_import/playbook/test_import_playbook.yml b/test/integration/targets/include_import/playbook/test_import_playbook.yml index e5910c4f1a7..9e266b340bb 100644 --- a/test/integration/targets/include_import/playbook/test_import_playbook.yml +++ b/test/integration/targets/include_import/playbook/test_import_playbook.yml @@ -20,3 +20,15 @@ # https://github.com/ansible/ansible/issues/59548 - import_playbook: sub_playbook/sub_playbook.yml + +- name: Use set_fact to declare a variable + hosts: localhost + gather_facts: no + tasks: + - set_fact: + a_var_from_set_fact: hello + +- name: Verify vars for import_playbook are not templated too early + import_playbook: playbook_using_a_var.yml + vars: + pb_var: "{{ a_var_from_set_fact }}"