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 -*-
|
|
|
|
# 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-08-16 03:16:38 +00:00
|
|
|
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
2017-03-14 16:07:22 +00:00
|
|
|
'status': ['stableinterface'],
|
|
|
|
'supported_by': 'core'}
|
|
|
|
|
2016-12-06 10:35:05 +00:00
|
|
|
|
2014-09-26 01:01:01 +00:00
|
|
|
DOCUMENTATION = '''
|
|
|
|
---
|
2016-08-30 22:52:59 +00:00
|
|
|
author: "Allen Sanabria (@linuxdynasty)"
|
2014-09-26 01:01:01 +00:00
|
|
|
module: include_vars
|
|
|
|
short_description: Load variables from files, dynamically within a task.
|
|
|
|
description:
|
2017-03-23 01:50:28 +00:00
|
|
|
- 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.
|
2017-06-26 15:26:53 +00:00
|
|
|
- This module is also supported for Windows targets.
|
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:
|
|
|
|
version_added: "2.2"
|
|
|
|
description:
|
|
|
|
- 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.
|
2016-08-30 22:52:59 +00:00
|
|
|
dir:
|
|
|
|
version_added: "2.2"
|
|
|
|
description:
|
|
|
|
- The directory name from which the 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.
|
|
|
|
default: null
|
2016-07-25 01:32:04 +00:00
|
|
|
name:
|
|
|
|
version_added: "2.2"
|
|
|
|
description:
|
|
|
|
- The name of a variable into which assign the included vars, if omitted (null) they will be made top level vars.
|
|
|
|
default: null
|
2016-08-30 22:52:59 +00:00
|
|
|
depth:
|
|
|
|
version_added: "2.2"
|
|
|
|
description:
|
2017-02-13 15:35:04 +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.
|
2016-08-30 22:52:59 +00:00
|
|
|
default: 0
|
|
|
|
files_matching:
|
|
|
|
version_added: "2.2"
|
|
|
|
description:
|
2017-02-13 15:35:04 +00:00
|
|
|
- Limit the files that are loaded within any directory to this regular expression.
|
2016-08-30 22:52:59 +00:00
|
|
|
default: null
|
|
|
|
ignore_files:
|
|
|
|
version_added: "2.2"
|
|
|
|
description:
|
2017-02-13 15:35:04 +00:00
|
|
|
- List of file names to ignore.
|
2016-08-30 22:52:59 +00:00
|
|
|
default: null
|
2017-02-13 15:35:04 +00:00
|
|
|
extensions:
|
|
|
|
version_added: "2.3"
|
|
|
|
description:
|
|
|
|
- List of file extensions to read when using C(dir).
|
|
|
|
default: ['yaml', 'yml', 'json']
|
|
|
|
required: False
|
2014-09-26 01:01:01 +00:00
|
|
|
free-form:
|
|
|
|
description:
|
2016-07-25 01:32:04 +00:00
|
|
|
- This module allows you to specify the 'file' option directly w/o any other options.
|
2017-02-13 15:35:04 +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:
|
|
|
|
- This module is also supported for Windows targets.
|
2014-09-26 01:01:01 +00:00
|
|
|
'''
|
|
|
|
|
|
|
|
EXAMPLES = """
|
2017-02-13 15:35:04 +00:00
|
|
|
- name: Include vars of stuff.yml into the 'stuff' variable (2.2).
|
|
|
|
include_vars:
|
2016-07-25 01:32:04 +00:00
|
|
|
file: stuff.yml
|
|
|
|
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:
|
2016-11-15 20:21:47 +00:00
|
|
|
file: contingency_plan.yml
|
|
|
|
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.
|
|
|
|
include_vars: "{{ item }}"
|
2014-09-26 01:01:01 +00:00
|
|
|
with_first_found:
|
2016-11-15 20:21:47 +00:00
|
|
|
- "{{ ansible_distribution }}.yml"
|
|
|
|
- "{{ ansible_os_family }}.yml"
|
|
|
|
- "default.yml"
|
2014-09-26 01:01:01 +00:00
|
|
|
|
2017-02-13 15:35:04 +00:00
|
|
|
- name: bare include (free-form)
|
|
|
|
include_vars: myvars.yml
|
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:
|
2016-08-30 22:52:59 +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:
|
2016-08-30 22:52:59 +00:00
|
|
|
dir: 'vars/all'
|
|
|
|
name: test
|
|
|
|
|
2017-02-13 15:35:04 +00:00
|
|
|
- name: Include default extension files in vars/services (2.2)
|
|
|
|
include_vars:
|
2016-08-30 22:52:59 +00:00
|
|
|
dir: 'vars/services'
|
|
|
|
depth: 1
|
|
|
|
|
2017-02-13 15:35:04 +00:00
|
|
|
- name: Include only files matching bastion.yml (2.2)
|
|
|
|
include_vars:
|
2016-08-30 22:52:59 +00:00
|
|
|
dir: 'vars'
|
|
|
|
files_matching: 'bastion.yml'
|
|
|
|
|
2017-02-13 15:35:04 +00:00
|
|
|
- name: Include all .yml files except bastion.yml (2.3)
|
|
|
|
include_vars:
|
2016-08-30 22:52:59 +00:00
|
|
|
dir: 'vars'
|
|
|
|
ignore_files: 'bastion.yml'
|
2017-02-13 15:35:04 +00:00
|
|
|
extensions: ['yml']
|
2014-09-26 01:01:01 +00:00
|
|
|
"""
|
2017-05-13 11:28:41 +00:00
|
|
|
|
|
|
|
RETURN = '''
|
|
|
|
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
|
|
|
|
sample: [ '/path/to/file.yml', '/path/to/file.json' ]
|
|
|
|
version_added: 2.4
|
|
|
|
'''
|