Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
5c4ed725
Commit
5c4ed725
authored
Apr 06, 2013
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Demo of parameterized roles!
parent
f308194b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
5 deletions
+32
-5
examples/playbooks/roles/foo/tasks/main.yml
+5
-0
examples/playbooks/roletest.yml
+11
-3
lib/ansible/playbook/play.py
+16
-2
No files found.
examples/playbooks/roles/foo/tasks/main.yml
View file @
5c4ed725
...
@@ -7,3 +7,8 @@
...
@@ -7,3 +7,8 @@
template
:
src=foo.j2 dest=/tmp/roles_test2.txt
template
:
src=foo.j2 dest=/tmp/roles_test2.txt
notify
:
notify
:
-
blippy
-
blippy
-
name
:
demo that parameterized roles work
shell
:
echo just FYI, param1={{ param1 }}, param2 ={{ param2 }}
examples/playbooks/roletest.yml
View file @
5c4ed725
...
@@ -26,13 +26,21 @@
...
@@ -26,13 +26,21 @@
-
hosts
:
all
-
hosts
:
all
roles
:
roles
:
-
foo
# a role can be listed flat like this:
#
# - common
# - webservers
# but you can also pass variables to them, so they can be parameterized. You can call
# a role more than once with different parameters too. It might look like this:
-
{
role
:
foo
,
param1
:
1000
,
param2
:
2000
}
-
{
role
:
foo
,
param1
:
8000
,
param2
:
9000
}
# add as many roles as you like, roles takes a list of roles names
# add as many roles as you like, roles takes a list of roles names
# these paths can be qualified, but if bare, it will look from them in
# these paths can be qualified, but if bare, it will look from them in
# roles/$rolename relative to the playbook
# roles/$rolename relative to the playbook
#
# - bar
# explicit tasks and handlers can be used, but are not required.
# explicit tasks and handlers can be used, but are not required.
# they will run after the roles if present.
# they will run after the roles if present.
...
...
lib/ansible/playbook/play.py
View file @
5c4ed725
...
@@ -125,7 +125,20 @@ class Play(object):
...
@@ -125,7 +125,20 @@ class Play(object):
new_tasks
=
[]
new_tasks
=
[]
new_handlers
=
[]
new_handlers
=
[]
new_vars_files
=
[]
new_vars_files
=
[]
# variables if the role was parameterized (i.e. given as a hash)
has_dict
=
{}
for
orig_path
in
roles
:
for
orig_path
in
roles
:
if
type
(
orig_path
)
==
dict
:
# what, not a path?
role_name
=
orig_path
.
get
(
'role'
,
None
)
if
role_name
is
None
:
raise
errors
.
AnsibleError
(
"expected a role name in dictionary:
%
s"
%
orig_path
)
has_dict
=
orig_path
orig_path
=
role_name
path
=
utils
.
path_dwim
(
self
.
basedir
,
orig_path
)
path
=
utils
.
path_dwim
(
self
.
basedir
,
orig_path
)
if
not
os
.
path
.
isdir
(
path
)
and
not
orig_path
.
startswith
(
"."
)
and
not
orig_path
.
startswith
(
"/"
):
if
not
os
.
path
.
isdir
(
path
)
and
not
orig_path
.
startswith
(
"."
)
and
not
orig_path
.
startswith
(
"/"
):
path2
=
utils
.
path_dwim
(
self
.
basedir
,
os
.
path
.
join
(
'roles'
,
orig_path
))
path2
=
utils
.
path_dwim
(
self
.
basedir
,
os
.
path
.
join
(
'roles'
,
orig_path
))
...
@@ -138,9 +151,9 @@ class Play(object):
...
@@ -138,9 +151,9 @@ class Play(object):
handler
=
utils
.
path_dwim
(
self
.
basedir
,
os
.
path
.
join
(
path
,
'handlers'
,
'main.yml'
))
handler
=
utils
.
path_dwim
(
self
.
basedir
,
os
.
path
.
join
(
path
,
'handlers'
,
'main.yml'
))
vars_file
=
utils
.
path_dwim
(
self
.
basedir
,
os
.
path
.
join
(
path
,
'vars'
,
'main.yml'
))
vars_file
=
utils
.
path_dwim
(
self
.
basedir
,
os
.
path
.
join
(
path
,
'vars'
,
'main.yml'
))
if
os
.
path
.
isfile
(
task
):
if
os
.
path
.
isfile
(
task
):
new_tasks
.
append
(
dict
(
include
=
task
))
new_tasks
.
append
(
dict
(
include
=
task
,
vars
=
has_dict
))
if
os
.
path
.
isfile
(
handler
):
if
os
.
path
.
isfile
(
handler
):
new_handlers
.
append
(
dict
(
include
=
handler
))
new_handlers
.
append
(
dict
(
include
=
handler
,
vars
=
has_dict
))
if
os
.
path
.
isfile
(
vars_file
):
if
os
.
path
.
isfile
(
vars_file
):
new_vars_files
.
append
(
vars_file
)
new_vars_files
.
append
(
vars_file
)
...
@@ -155,6 +168,7 @@ class Play(object):
...
@@ -155,6 +168,7 @@ class Play(object):
vars_files
=
[]
vars_files
=
[]
tasks
.
extend
(
new_tasks
)
tasks
.
extend
(
new_tasks
)
handlers
.
extend
(
new_handlers
)
handlers
.
extend
(
new_handlers
)
vars_files
.
extend
(
new_vars_files
)
vars_files
.
extend
(
new_vars_files
)
ds
[
'tasks'
]
=
tasks
ds
[
'tasks'
]
=
tasks
ds
[
'handlers'
]
=
handlers
ds
[
'handlers'
]
=
handlers
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment