2019-03-06 23:25:59 +00:00
|
|
|
#!/usr/bin/python
|
Remove wildcard imports
Made the following changes:
* Removed wildcard imports
* Replaced long form of GPL header with short form
* Removed get_exception usage
* Added from __future__ boilerplate
* Adjust division operator to // where necessary
For the following files:
* web_infrastructure modules
* system modules
* linode, lxc, lxd, atomic, cloudscale, dimensiondata, ovh, packet,
profitbricks, pubnub, smartos, softlayer, univention modules
* compat dirs (disabled as its used intentionally)
2017-07-28 05:55:24 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2019-03-06 23:25:59 +00:00
|
|
|
|
Remove wildcard imports
Made the following changes:
* Removed wildcard imports
* Replaced long form of GPL header with short form
* Removed get_exception usage
* Added from __future__ boilerplate
* Adjust division operator to // where necessary
For the following files:
* web_infrastructure modules
* system modules
* linode, lxc, lxd, atomic, cloudscale, dimensiondata, ovh, packet,
profitbricks, pubnub, smartos, softlayer, univention modules
* compat dirs (disabled as its used intentionally)
2017-07-28 05:55:24 +00:00
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
|
__metaclass__ = type
|
2014-09-26 01:01:01 +00:00
|
|
|
|
2017-11-22 22:05:29 +00:00
|
|
|
ANSIBLE_METADATA = {
|
|
|
|
'metadata_version': '1.1',
|
|
|
|
'status': ['stableinterface'],
|
|
|
|
'supported_by': 'core'
|
|
|
|
}
|
2017-03-14 16:07:22 +00:00
|
|
|
|
2019-03-06 23:25:59 +00:00
|
|
|
DOCUMENTATION = r'''
|
2014-09-26 01:01:01 +00:00
|
|
|
---
|
2017-11-22 22:05:29 +00:00
|
|
|
author: Allen Sanabria (@linuxdynasty)
|
2014-09-26 01:01:01 +00:00
|
|
|
module: include_vars
|
2017-11-22 22:05:29 +00:00
|
|
|
short_description: Load variables from files, dynamically within a task
|
2014-09-26 01:01:01 +00:00
|
|
|
description:
|
2018-09-12 19:30:05 +00:00
|
|
|
- Loads YAML/JSON variables dynamically from a file or directory, recursively, during task runtime.
|
|
|
|
- If loading a directory, the files are sorted alphabetically before being loaded.
|
2017-11-22 22:05:29 +00:00
|
|
|
- This module is also supported for Windows targets.
|
2018-09-12 19:30:05 +00:00
|
|
|
- To assign included variables to a different host than C(inventory_hostname),
|
2019-03-06 23:25:59 +00:00
|
|
|
use C(delegate_to) and set C(delegate_facts=yes).
|
2016-11-04 02:07:04 +00:00
|
|
|
version_added: "1.4"
|
2014-09-26 01:01:01 +00:00
|
|
|
options:
|
2016-07-25 01:32:04 +00:00
|
|
|
file:
|
|
|
|
description:
|
2017-11-22 22:05:29 +00:00
|
|
|
- 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.
|
2019-03-06 23:25:59 +00:00
|
|
|
type: path
|
2016-08-30 22:52:59 +00:00
|
|
|
version_added: "2.2"
|
2019-03-06 23:25:59 +00:00
|
|
|
dir:
|
2016-08-30 22:52:59 +00:00
|
|
|
description:
|
|
|
|
- The directory name from which the variables should be loaded.
|
2019-02-11 18:25:51 +00:00
|
|
|
- If the path is relative and the task is inside a role, it will look inside the role's vars/ subdirectory.
|
|
|
|
- If the path is relative and not inside a role, it will be parsed relative to the playbook.
|
2019-03-06 23:25:59 +00:00
|
|
|
type: path
|
2016-07-25 01:32:04 +00:00
|
|
|
version_added: "2.2"
|
2019-03-06 23:25:59 +00:00
|
|
|
name:
|
2016-07-25 01:32:04 +00:00
|
|
|
description:
|
2019-03-06 23:25:59 +00:00
|
|
|
- The name of a variable into which assign the included vars.
|
|
|
|
- If omitted (null) they will be made top level vars.
|
|
|
|
type: str
|
2016-08-30 22:52:59 +00:00
|
|
|
version_added: "2.2"
|
2019-03-06 23:25:59 +00:00
|
|
|
depth:
|
2016-08-30 22:52:59 +00:00
|
|
|
description:
|
2017-11-22 22:05:29 +00:00
|
|
|
- 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.
|
2019-03-06 23:25:59 +00:00
|
|
|
type: int
|
2016-08-30 22:52:59 +00:00
|
|
|
default: 0
|
|
|
|
version_added: "2.2"
|
2019-03-06 23:25:59 +00:00
|
|
|
files_matching:
|
2016-08-30 22:52:59 +00:00
|
|
|
description:
|
2017-02-13 15:35:04 +00:00
|
|
|
- Limit the files that are loaded within any directory to this regular expression.
|
2019-03-06 23:25:59 +00:00
|
|
|
type: str
|
2016-08-30 22:52:59 +00:00
|
|
|
version_added: "2.2"
|
2019-03-06 23:25:59 +00:00
|
|
|
ignore_files:
|
2016-08-30 22:52:59 +00:00
|
|
|
description:
|
2017-02-13 15:35:04 +00:00
|
|
|
- List of file names to ignore.
|
2019-03-06 23:25:59 +00:00
|
|
|
type: list
|
|
|
|
version_added: "2.2"
|
2017-02-13 15:35:04 +00:00
|
|
|
extensions:
|
|
|
|
description:
|
|
|
|
- List of file extensions to read when using C(dir).
|
2019-03-06 23:25:59 +00:00
|
|
|
type: list
|
|
|
|
default: [ json, yaml, yml ]
|
|
|
|
version_added: "2.3"
|
2018-07-26 03:43:01 +00:00
|
|
|
ignore_unknown_extensions:
|
2018-05-31 19:30:49 +00:00
|
|
|
description:
|
2019-03-06 23:25:59 +00:00
|
|
|
- Ignore unknown file extensions within the directory.
|
|
|
|
- This allows users to specify a directory containing vars files that are intermingled with non-vars files extension types
|
|
|
|
(e.g. a directory with a README in it and vars files).
|
|
|
|
type: bool
|
|
|
|
default: no
|
|
|
|
version_added: "2.7"
|
2014-09-26 01:01:01 +00:00
|
|
|
free-form:
|
|
|
|
description:
|
2017-11-22 22:05:29 +00:00
|
|
|
- This module allows you to specify the 'file' option directly without any other options.
|
2019-03-06 23:25:59 +00:00
|
|
|
- There is no 'free-form' option, this is just an indicator, see example below.
|
2017-06-26 15:26:53 +00:00
|
|
|
notes:
|
2017-11-22 22:05:29 +00:00
|
|
|
- This module is also supported for Windows targets.
|
2019-03-06 23:25:59 +00:00
|
|
|
seealso:
|
|
|
|
- module: set_fact
|
|
|
|
- ref: playbooks_delegation
|
|
|
|
description: More information related to task delegation.
|
2014-09-26 01:01:01 +00:00
|
|
|
'''
|
|
|
|
|
2019-03-06 23:25:59 +00:00
|
|
|
EXAMPLES = r'''
|
2017-11-22 22:05:29 +00:00
|
|
|
- name: Include vars of stuff.yaml into the 'stuff' variable (2.2).
|
2017-02-13 15:35:04 +00:00
|
|
|
include_vars:
|
2017-11-22 22:05:29 +00:00
|
|
|
file: stuff.yaml
|
2016-07-25 01:32:04 +00:00
|
|
|
name: stuff
|
|
|
|
|
2017-02-13 15:35:04 +00:00
|
|
|
- name: Conditionally decide to load in variables into 'plans' when x is 0, otherwise do not. (2.2)
|
|
|
|
include_vars:
|
2017-11-22 22:05:29 +00:00
|
|
|
file: contingency_plan.yaml
|
2016-11-15 20:21:47 +00:00
|
|
|
name: plans
|
2014-09-26 01:01:01 +00:00
|
|
|
when: x == 0
|
|
|
|
|
2017-02-13 15:35:04 +00:00
|
|
|
- name: Load a variable file based on the OS type, or a default if not found. Using free-form to specify the file.
|
2018-09-12 19:35:04 +00:00
|
|
|
include_vars: "{{ lookup('first_found', possible_files) }}"
|
|
|
|
vars:
|
|
|
|
possible_files:
|
|
|
|
- "{{ ansible_distribution }}.yaml"
|
|
|
|
- "{{ ansible_os_family }}.yaml"
|
|
|
|
- default.yaml
|
2014-09-26 01:01:01 +00:00
|
|
|
|
2017-11-22 22:05:29 +00:00
|
|
|
- name: Bare include (free-form)
|
|
|
|
include_vars: myvars.yaml
|
2016-07-25 01:32:04 +00:00
|
|
|
|
2017-02-13 15:35:04 +00:00
|
|
|
- name: Include all .json and .jsn files in vars/all and all nested directories (2.3)
|
|
|
|
include_vars:
|
2017-11-22 22:05:29 +00:00
|
|
|
dir: vars/all
|
2017-02-13 15:35:04 +00:00
|
|
|
extensions:
|
|
|
|
- json
|
|
|
|
- jsn
|
2016-08-30 22:52:59 +00:00
|
|
|
|
2017-02-13 15:35:04 +00:00
|
|
|
- name: Include all default extension files in vars/all and all nested directories and save the output in test. (2.2)
|
|
|
|
include_vars:
|
2017-11-22 22:05:29 +00:00
|
|
|
dir: vars/all
|
2016-08-30 22:52:59 +00:00
|
|
|
name: test
|
|
|
|
|
2017-02-13 15:35:04 +00:00
|
|
|
- name: Include default extension files in vars/services (2.2)
|
|
|
|
include_vars:
|
2017-11-22 22:05:29 +00:00
|
|
|
dir: vars/services
|
2016-08-30 22:52:59 +00:00
|
|
|
depth: 1
|
|
|
|
|
2017-11-22 22:05:29 +00:00
|
|
|
- name: Include only files matching bastion.yaml (2.2)
|
2017-02-13 15:35:04 +00:00
|
|
|
include_vars:
|
2017-11-22 22:05:29 +00:00
|
|
|
dir: vars
|
|
|
|
files_matching: bastion.yaml
|
2016-08-30 22:52:59 +00:00
|
|
|
|
2017-11-22 22:05:29 +00:00
|
|
|
- name: Include all .yaml files except bastion.yaml (2.3)
|
2017-02-13 15:35:04 +00:00
|
|
|
include_vars:
|
2017-11-22 22:05:29 +00:00
|
|
|
dir: vars
|
2018-05-23 19:35:02 +00:00
|
|
|
ignore_files: [bastion.yaml]
|
2017-11-22 22:05:29 +00:00
|
|
|
extensions: [yaml]
|
2019-01-22 17:56:10 +00:00
|
|
|
|
|
|
|
- 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']
|
2019-03-06 23:25:59 +00:00
|
|
|
'''
|
2017-05-13 11:28:41 +00:00
|
|
|
|
2019-03-06 23:25:59 +00:00
|
|
|
RETURN = r'''
|
2017-05-13 11:28:41 +00:00
|
|
|
ansible_facts:
|
|
|
|
description: Variables that were included and their values
|
|
|
|
returned: success
|
|
|
|
type: dict
|
|
|
|
sample: {'variable': 'value'}
|
|
|
|
ansible_included_var_files:
|
|
|
|
description: A list of files that were successfully included
|
|
|
|
returned: success
|
|
|
|
type: list
|
2019-03-06 23:25:59 +00:00
|
|
|
sample: [ /path/to/file.json, /path/to/file.yaml ]
|
|
|
|
version_added: '2.4'
|
2017-05-13 11:28:41 +00:00
|
|
|
'''
|