mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 20:01:25 -07:00
added 'extensions' options to include_vars
This allows users to override default 'extensions read' when using the dir option
This commit is contained in:
parent
48c6dd2689
commit
93ac278f4c
2 changed files with 46 additions and 28 deletions
|
@ -18,8 +18,7 @@ author: "Allen Sanabria (@linuxdynasty)"
|
|||
module: include_vars
|
||||
short_description: Load variables from files, dynamically within a task.
|
||||
description:
|
||||
- Loads variables from a YAML/JSON files dynamically from within a file or
|
||||
from a directory recursively during task runtime. If loading a directory, the files are sorted alphabetically before being loaded.
|
||||
- Loads variables from a YAML/JSON files dynamically from within a file or from a directory recursively during task runtime. If loading a directory, the files are sorted alphabetically before being loaded.
|
||||
version_added: "1.4"
|
||||
options:
|
||||
file:
|
||||
|
@ -41,66 +40,78 @@ options:
|
|||
depth:
|
||||
version_added: "2.2"
|
||||
description:
|
||||
- By default, this module will recursively go through each sub directory and load up the variables. By explicitly setting the depth, this module will only go as deep as the depth.
|
||||
- When using C(dir), this module will, by default, recursively go through each sub directory and load up the variables.
|
||||
By explicitly setting the depth, this module will only go as deep as the depth.
|
||||
default: 0
|
||||
files_matching:
|
||||
version_added: "2.2"
|
||||
description:
|
||||
- Limit the variables that are loaded within any directory to this regular expression.
|
||||
- Limit the files that are loaded within any directory to this regular expression.
|
||||
default: null
|
||||
ignore_files:
|
||||
version_added: "2.2"
|
||||
description:
|
||||
- List of file names to ignore. The defaults can not be overridden, but can be extended.
|
||||
- List of file names to ignore.
|
||||
default: null
|
||||
extensions:
|
||||
version_added: "2.3"
|
||||
description:
|
||||
- List of file extensions to read when using C(dir).
|
||||
default: ['yaml', 'yml', 'json']
|
||||
required: False
|
||||
free-form:
|
||||
description:
|
||||
- This module allows you to specify the 'file' option directly w/o any other options.
|
||||
There is no 'free-form' option, this is just an indicator, see example below.
|
||||
'''
|
||||
|
||||
EXAMPLES = """
|
||||
# Include vars of stuff.yml into the 'stuff' variable (2.2).
|
||||
- include_vars:
|
||||
- name: 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:
|
||||
- name: 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 }}"
|
||||
- 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: "{{ item }}"
|
||||
with_first_found:
|
||||
- "{{ ansible_distribution }}.yml"
|
||||
- "{{ ansible_os_family }}.yml"
|
||||
- "default.yml"
|
||||
|
||||
# bare include (free-form)
|
||||
- include_vars: myvars.yml
|
||||
- name: bare include (free-form)
|
||||
include_vars: myvars.yml
|
||||
|
||||
# Include all yml files in vars/all and all nested directories
|
||||
- include_vars:
|
||||
- name: Include all .json and .jsn files in vars/all and all nested directories (2.3)
|
||||
include_vars:
|
||||
dir: 'vars/all'
|
||||
extensions:
|
||||
- json
|
||||
- jsn
|
||||
|
||||
# Include all yml files in vars/all and all nested directories and save the output in test.
|
||||
- include_vars:
|
||||
- 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
|
||||
|
||||
# Include all yml files in vars/services
|
||||
- include_vars:
|
||||
- name: Include default extension files in vars/services (2.2)
|
||||
include_vars:
|
||||
dir: 'vars/services'
|
||||
depth: 1
|
||||
|
||||
# Include only bastion.yml files
|
||||
- include_vars:
|
||||
- name: Include only files matching bastion.yml (2.2)
|
||||
include_vars:
|
||||
dir: 'vars'
|
||||
files_matching: 'bastion.yml'
|
||||
|
||||
# Include only all yml files exception bastion.yml
|
||||
- include_vars:
|
||||
- name: Include all .yml files except bastion.yml (2.3)
|
||||
include_vars:
|
||||
dir: 'vars'
|
||||
ignore_files: 'bastion.yml'
|
||||
extensions: ['yml']
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue