blob: 79f4a78f0b625bc88b407abe9d03649edb4cf16b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
- name: Test include_role
hosts: testhost
vars:
run_role: yes
do_not_run_role: no
role_name: role1
test_var: templating test in playbook
role_vars:
where_am_i_defined: in the playbook
entire_task:
include_role:
name: role1
tasks:
- name: Test basic role include
include_role:
name: role1
- name: Assert that basic include works
assert:
that:
- _role1_result.msg == 'In role1'
- name: Test conditional role include
include_role:
name: role1
tasks_from: canary1.yml
when: run_role
- name: Assert that role ran
assert:
that:
- role1_canary1 == 'r1c1'
- name: Test conditional role include that should be skipped
include_role:
name: role1
tasks_from: canary2.yml
when: do_not_run_role
- name: Assert that role did not run
assert:
that:
- role1_canary2 is not defined
- name: Test role include with a loop
include_role:
name: "{{ item }}"
register: loop_test
with_items:
- role1
- role3
- role2
- name: Test including a task file from a role
include_role:
name: role1
tasks_from: tasks.yml
- name: Test including vars file and tasks file from a role
include_role:
name: role3
tasks_from: vartest.yml
vars_from: role3vars.yml
private: no
# FIXME Setting private: no in previous task does not make the variables
# available to the play
- name: Assert that variables defined in previous task are available to play
assert:
that:
- role3_default == 'defined in role3/defaults/main.yml'
- role3_main == 'defined in role3/vars/main.yml'
- role3_var == 'defined in role3/vars/role3vars.yml'
ignore_errors: yes
- name: Test using a play variable for role name
include_role:
name: "{{ role_name }}"
- name: Test using a host variable for role name
include_role:
name: "{{ host_var_role_name }}"
- name: Pass variable to role
include_role:
name: role1
tasks_from: vartest.yml
vars:
where_am_i_defined: in the task
## FIXME Currently failing with
## ERROR! Vars in a IncludeRole must be specified as a dictionary, or a list of dictionaries
# - name: Pass all variables in a variable to role
# include_role:
# name: role1
# tasks_from: vartest.yml
# vars: "{{ role_vars }}"
- name: Pass templated variable to a role
include_role:
name: role1
tasks_from: vartest.yml
vars:
where_am_i_defined: "{{ test_var }}"
## FIXME This fails with the following error:
## The module {u'include_role': {u'name': u'role1'}} was not found in configured module paths.
# - name: Include an entire task
# action:
# module: "{{ entire_task }}"
- block:
- name: Include a role that will fail
include_role:
name: role1
tasks_from: fail.yml
rescue:
- name: Include a role inside rescue
include_role:
name: role2
always:
- name: Include role inside always
include_role:
name: role3
|