Debian Codegraph @

lib/ansible/modules/import_role.py

raw
1 # -*- coding: utf-8 -*-
2 # Copyright: Ansible Project
3 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
4
5 from __future__ import annotations
6
7
8 DOCUMENTATION = r"""
9 ---
10 author: Ansible Core Team (@ansible)
11 module: import_role
12 short_description: Import a role into a play
13 description:
14 - Much like the C(roles:) keyword, this task loads a role, but it allows you to control when the role tasks run in
15 between other tasks of the play.
16 - Most keywords, loops and conditionals will only be applied to the imported tasks, not to this statement itself. If
17 you want the opposite behavior, use M(ansible.builtin.include_role) instead.
18 - Does not work in handlers.
19 version_added: '2.4'
20 options:
21 name:
22 description:
23 - The name of the role to be executed.
24 type: str
25 required: true
26 tasks_from:
27 description:
28 - File to load from a role's C(tasks/) directory.
29 type: str
30 default: main
31 vars_from:
32 description:
33 - File to load from a role's C(vars/) directory.
34 type: str
35 default: main
36 defaults_from:
37 description:
38 - File to load from a role's C(defaults/) directory.
39 type: str
40 default: main
41 allow_duplicates:
42 description:
43 - Overrides the role's metadata setting to allow using a role more than once with the same parameters.
44 type: bool
45 default: yes
46 handlers_from:
47 description:
48 - File to load from a role's C(handlers/) directory.
49 type: str
50 default: main
51 version_added: '2.8'
52 rolespec_validate:
53 description:
54 - Perform role argument spec validation if an argument spec is defined.
55 type: bool
56 default: yes
57 version_added: '2.11'
58 public:
59 description:
60 - This option dictates whether the role's C(vars) and C(defaults) are exposed to the play.
61 - Variables are exposed to the play at playbook parsing time, and available to earlier roles and tasks as well unlike C(include_role).
62 - The default depends on the configuration option R(DEFAULT_PRIVATE_ROLE_VARS, DEFAULT_PRIVATE_ROLE_VARS).
63 type: bool
64 default: yes
65 version_added: '2.17'
66 extends_documentation_fragment:
67 - action_common_attributes
68 - action_common_attributes.conn
69 - action_common_attributes.flow
70 - action_core
71 - action_core.import
72 attributes:
73 check_mode:
74 support: full
75 diff_mode:
76 support: none
77 notes:
78 - Handlers are made available to the whole play.
79 - Since Ansible 2.7 variables defined in C(vars) and C(defaults) for the role are exposed to the play at playbook parsing time.
80 Due to this, these variables will be accessible to roles and tasks executed before the location of the
81 M(ansible.builtin.import_role) task.
82 - Unlike M(ansible.builtin.include_role) variable exposure is not configurable, and will always be exposed.
83 seealso:
84 - module: ansible.builtin.import_playbook
85 - module: ansible.builtin.import_tasks
86 - module: ansible.builtin.include_role
87 - module: ansible.builtin.include_tasks
88 - ref: playbooks_reuse
89 description: More information related to including and importing playbooks, roles and tasks.
90 """
91
92 EXAMPLES = r"""
93 - hosts: all
94 tasks:
95 - ansible.builtin.import_role:
96 name: myrole
97
98 - name: Run tasks/other.yaml instead of 'main'
99 ansible.builtin.import_role:
100 name: myrole
101 tasks_from: other
102
103 - name: Pass variables to role
104 ansible.builtin.import_role:
105 name: myrole
106 vars:
107 rolevar1: value from task
108
109 - name: Apply condition to each task in role
110 ansible.builtin.import_role:
111 name: myrole
112 when: not idontwanttorun
113 """
114
115 RETURN = r"""
116 # This module does not return anything except tasks to execute.
117 """