Content of vars.yaml
---
symfony_root_dir: /var/www/project
symfony_web_dir: "{{ symfony_root_dir }}/web"
symfony_var_dir: "{{ symfony_root_dir }}/var"
symfony_console_path: "{{ symfony_root_dir }}/bin/console"
Content of first.tf
---
- hosts: myhosts
tasks:
- name: include default step variables
include_vars: default_step.yml
# roles/test/tasks/main.yml
---
- include_vars:
file: subdir/bar
name: foo
- debug:
var: foo
# Conditionally decide to load in variables when x is 0, otherwise do not.
- include_vars: contingency_plan.yml
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"
# example-05.yml
---
- hosts: localhost
connection: local
tasks:
- debug:
var: variable_include_vars_five
- include_vars: 'variable_include_vars_five.yml'
- debug:
var: variable_include_vars_five
# variable_include_vars_five.yml
---
variable_include_vars_five: 'set-via-include-vars-file'
# example-05.yml
---
- hosts: localhost
connection: local
tasks:
- debug:
var: variable_include_vars_five
- include_vars: 'variable_include_vars_five.yml'
- debug:
var: variable_include_vars_five
# variable_include_vars_five.yml
---
variable_include_vars_five: 'set-via-include-vars-file'
- name: Include vars of stuff.yaml into the 'stuff' variable (2.2).
include_vars:
file: stuff.yaml
name: stuff
- name: Conditionally decide to load in variables into 'plans' when x is 0, otherwise do not. (2.2)
include_vars:
file: contingency_plan.yaml
name: plans
when: x == 0
- name: Load a variable file based on the OS type, or a default if not found. Using free-form to specify the file.
include_vars: "{{ lookup('first_found', possible_files) }}"
vars:
possible_files:
- "{{ ansible_distribution }}.yaml"
- "{{ ansible_os_family }}.yaml"
- default.yaml
- name: Bare include (free-form)
include_vars: myvars.yaml
- name: Include all .json and .jsn files in vars/all and all nested directories (2.3)
include_vars:
dir: vars/all
extensions:
- json
- jsn
- name: Include all default extension files in vars/all and all nested directories and save the output in test. (2.2)
include_vars:
dir: vars/all
name: test
- name: Include default extension files in vars/services (2.2)
include_vars:
dir: vars/services
depth: 1
- name: Include only files matching bastion.yaml (2.2)
include_vars:
dir: vars
files_matching: bastion.yaml
- name: Include all .yaml files except bastion.yaml (2.3)
include_vars:
dir: vars
ignore_files: [bastion.yaml]
extensions: [yaml]
- name: Ignore warnings raised for files with unknown extensions while loading (2.7)
include_vars:
dir: vars
ignore_unknown_extensions: True
extensions: ['', 'yaml', 'yml', 'json']