How to pass variables to included tasks in ansible? Just use {{ some_other_var }} in task and it should work fine You shouldn't need to explicitly pass my_var to the include All variables including extra-vars should be directly available everywhere
How to Include Variables in Ansible [5 Examples] - Linux Handbook The include_vars module allows to include variables from an external file into your playbooks This is useful when you want to organize your variables in separate files for better readability and reusability
Boost Ansible Playbooks with include_vars: Dynamic Variable Management Dynamic Variable Loading This module allows you to load variables from external files during the execution of a task This is incredibly useful for: Centralized Configuration Keep your variables organized in separate files, making your playbooks more modular and easier to manage
Ansible Playbook variables and facts | Red Hat Developer You can include variable files in your playbook using the vars_files section or the ansible builtin include_vars module Let’s use an example to include a variable file in a playbook:
How to use a variable in a vars file - Ansible Project - Ansible How do you source the vars file? You have two options A vars_files directive before the tasks section vars_files: your_vars_file yml A task that explicitly includes a vars file include_vars: file: your_vars_file yml There are other variants of this so read the docs on the ansible website Walter
ansible - How can I import all variable files from a directory which is . . . Since your first trial indicates that you are fine with having the variables files included at the play level, you could use an include_vars task in a pre_tasks: pre_tasks: - name: Include all vars files ansible builtin include_vars: dir: vars external_vars roles: - role: roles users