2016-08-26 17:07:28 +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 -*-
|
|
|
|
# Copyright: Ansible Project
|
|
|
|
# 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
|
|
|
|
|
2016-08-26 17:07:28 +00:00
|
|
|
|
2017-11-22 22:05:29 +00:00
|
|
|
ANSIBLE_METADATA = {
|
|
|
|
'metadata_version': '1.1',
|
|
|
|
'status': ['preview'],
|
|
|
|
'supported_by': 'core'
|
|
|
|
}
|
2017-03-14 16:07:22 +00:00
|
|
|
|
2016-12-06 10:35:05 +00:00
|
|
|
|
2016-08-26 17:07:28 +00:00
|
|
|
DOCUMENTATION = '''
|
|
|
|
---
|
2017-11-22 22:05:29 +00:00
|
|
|
author: Ansible Core Team (@ansible)
|
2016-08-26 17:07:28 +00:00
|
|
|
module: include_role
|
|
|
|
short_description: Load and execute a role
|
|
|
|
description:
|
2017-11-22 22:05:29 +00:00
|
|
|
- Loads and executes a role as a task dynamically. This frees roles from the `roles:` directive and allows them to be
|
|
|
|
treated more as tasks.
|
|
|
|
- Unlike M(import_role), most keywords, including loops and conditionals, apply to this statement.
|
|
|
|
- This module is also supported for Windows targets.
|
2016-08-26 17:07:28 +00:00
|
|
|
version_added: "2.2"
|
|
|
|
options:
|
2018-05-31 17:08:38 +00:00
|
|
|
apply:
|
|
|
|
description:
|
|
|
|
- Accepts a hash of task keywords (e.g. C(tags), C(become)) that will be applied to the tasks within the include.
|
|
|
|
version_added: '2.7'
|
2016-08-26 17:07:28 +00:00
|
|
|
name:
|
|
|
|
description:
|
|
|
|
- The name of the role to be executed.
|
|
|
|
required: True
|
|
|
|
tasks_from:
|
|
|
|
description:
|
2017-11-22 22:05:29 +00:00
|
|
|
- File to load from a role's C(tasks/) directory.
|
|
|
|
default: main
|
2016-08-27 01:55:40 +00:00
|
|
|
vars_from:
|
|
|
|
description:
|
2017-11-22 22:05:29 +00:00
|
|
|
- File to load from a role's C(vars/) directory.
|
|
|
|
default: main
|
2016-08-27 01:55:40 +00:00
|
|
|
defaults_from:
|
|
|
|
description:
|
2017-11-22 22:05:29 +00:00
|
|
|
- File to load from a role's C(defaults/) directory.
|
|
|
|
default: main
|
2016-10-18 15:17:39 +00:00
|
|
|
allow_duplicates:
|
|
|
|
description:
|
|
|
|
- Overrides the role's metadata setting to allow using a role more than once with the same parameters.
|
2018-03-15 21:15:24 +00:00
|
|
|
type: bool
|
|
|
|
default: 'yes'
|
2016-09-06 18:05:15 +00:00
|
|
|
private:
|
|
|
|
description:
|
2018-05-08 15:31:56 +00:00
|
|
|
- This option is a no op, and the functionality described in previous versions was not implemented. This
|
|
|
|
option will be removed in Ansible v2.8.
|
2018-03-15 21:15:24 +00:00
|
|
|
type: bool
|
2018-05-01 17:19:04 +00:00
|
|
|
default: 'no'
|
2016-08-26 17:07:28 +00:00
|
|
|
notes:
|
2017-11-22 22:05:29 +00:00
|
|
|
- Handlers are made available to the whole play.
|
|
|
|
- Before Ansible 2.4, as with C(include), this task could be static or dynamic, If static, it implied that it won't
|
|
|
|
need templating, loops or conditionals and will show included tasks in the `--list` options. Ansible would try to
|
|
|
|
autodetect what is needed, but you can set `static` to `yes` or `no` at task level to control this.
|
|
|
|
- After Ansible 2.4, you can use M(import_role) for 'static' behaviour and this action for 'dynamic' one.
|
2016-08-26 17:07:28 +00:00
|
|
|
'''
|
|
|
|
|
|
|
|
EXAMPLES = """
|
2016-11-15 20:21:47 +00:00
|
|
|
- include_role:
|
|
|
|
name: myrole
|
2016-08-26 17:07:28 +00:00
|
|
|
|
2017-11-22 22:05:29 +00:00
|
|
|
- name: Run tasks/other.yaml instead of 'main'
|
2016-08-26 17:07:28 +00:00
|
|
|
include_role:
|
2016-09-14 14:15:48 +00:00
|
|
|
name: myrole
|
2016-08-26 17:07:28 +00:00
|
|
|
tasks_from: other
|
|
|
|
|
|
|
|
- name: Pass variables to role
|
|
|
|
include_role:
|
|
|
|
name: myrole
|
|
|
|
vars:
|
2017-11-22 22:05:29 +00:00
|
|
|
rolevar1: value from task
|
2016-08-26 17:07:28 +00:00
|
|
|
|
2016-09-06 18:05:15 +00:00
|
|
|
- name: Use role in loop
|
|
|
|
include_role:
|
|
|
|
name: myrole
|
|
|
|
with_items:
|
2016-12-09 10:59:50 +00:00
|
|
|
- '{{ roleinput1 }}'
|
|
|
|
- '{{ roleinput2 }}'
|
2016-09-06 18:05:15 +00:00
|
|
|
loop_control:
|
|
|
|
loop_var: roleinputvar
|
|
|
|
|
2017-11-22 22:05:29 +00:00
|
|
|
- name: Conditional role
|
2016-09-06 18:05:15 +00:00
|
|
|
include_role:
|
|
|
|
name: myrole
|
|
|
|
when: not idontwanttorun
|
2018-05-31 17:08:38 +00:00
|
|
|
|
|
|
|
- name: Apply tags to tasks within included file
|
|
|
|
include_role:
|
|
|
|
name: install
|
|
|
|
apply:
|
|
|
|
tags:
|
|
|
|
- install
|
|
|
|
tags:
|
|
|
|
- always
|
2016-08-26 17:07:28 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
RETURN = """
|
2017-11-22 22:05:29 +00:00
|
|
|
# This module does not return anything except tasks to execute.
|
2016-08-26 17:07:28 +00:00
|
|
|
"""
|