New in version 1.4.
Loads variables from a YAML/JSON file dynamically during task runtime. It can work with conditionals, or use host specific variables to determine the path name to load from.
| parameter | required | default | choices | comments |
|---|---|---|---|---|
| file (added in 2.2)
| no |
The file name from which variables should be loaded.
If the path is relative, it will look for the file in vars/ subdirectory of a role or relative to playbook.
|
||
| free-form | no | This module allows you to specify the 'file' option directly w/o any other options. |
||
| name (added in 2.2)
| no | The name of a variable into which assign the included vars, if omitted (null) they will be made top level vars. |
# Include vars of stuff.yml into the 'stuff' variable (2.2).
- include_vars:
file: stuff.yml
name: stuff
# Conditionally decide to load in variables into 'plans' when x is 0, otherwise do not. (2.2)
- include_vars: file=contingency_plan.yml name=plans
when: x == 0
# Load a variable file based on the OS type, or a default if not found.
- include_vars: "{{ item }}"
with_first_found:
- "{{ ansible_distribution }}.yml"
- "{{ ansible_os_family }}.yml"
- "default.yml"
# bare include (free-form)
- include_vars: myvars.yml
Note
The file is always required either as the explicit option or using the free-form.
For more information on what this means please read Core Modules
For help in developing on modules, should you be so inclined, please read Community Information & Contributing, developing_test_pr and Developing Modules.
© 2012–2016 Michael DeHaan
© 2016 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/include_vars_module.html