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
ecc7f8cb
Commit
ecc7f8cb
authored
Jul 20, 2013
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'sudo_role' into devel
parents
32d5038d
c10c2cae
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
13 deletions
+24
-13
lib/ansible/playbook/play.py
+24
-13
No files found.
lib/ansible/playbook/play.py
View file @
ecc7f8cb
...
...
@@ -160,8 +160,12 @@ class Play(object):
has_dict
=
orig_path
orig_path
=
role_name
with_items
=
has_dict
.
get
(
'with_items'
,
None
)
when
=
has_dict
.
get
(
'when'
,
None
)
# special vars must be extracted from the dict to the included tasks
special_keys
=
[
"sudo"
,
"sudo_user"
,
"when"
,
"with_items"
]
special_vars
=
{}
for
k
in
special_keys
:
if
k
in
has_dict
:
special_vars
[
k
]
=
has_dict
[
k
]
path
=
utils
.
path_dwim
(
self
.
basedir
,
os
.
path
.
join
(
'roles'
,
orig_path
))
if
not
os
.
path
.
isdir
(
path
)
and
not
orig_path
.
startswith
(
"."
)
and
not
orig_path
.
startswith
(
"/"
):
...
...
@@ -182,17 +186,15 @@ class Play(object):
raise
errors
.
AnsibleError
(
"found role at
%
s, but cannot find
%
s or
%
s or
%
s or
%
s"
%
(
path
,
task
,
handler
,
vars_file
,
library
))
if
os
.
path
.
isfile
(
task
):
nt
=
dict
(
include
=
task
,
vars
=
has_dict
)
if
when
:
nt
[
'when'
]
=
when
if
with_items
:
nt
[
'with_items'
]
=
with_items
for
k
in
special_keys
:
if
k
in
special_vars
:
nt
[
k
]
=
special_vars
[
k
]
new_tasks
.
append
(
nt
)
if
os
.
path
.
isfile
(
handler
):
nt
=
dict
(
include
=
handler
,
vars
=
has_dict
)
if
when
:
nt
[
'when'
]
=
when
if
with_items
:
nt
[
'with_items'
]
=
with_items
for
k
in
special_keys
:
if
k
in
special_vars
:
nt
[
k
]
=
special_vars
[
k
]
new_handlers
.
append
(
nt
)
if
os
.
path
.
isfile
(
vars_file
):
new_vars_files
.
append
(
vars_file
)
...
...
@@ -248,7 +250,7 @@ class Play(object):
# *************************************************
def
_load_tasks
(
self
,
tasks
,
vars
=
{},
additional_conditions
=
[],
original_file
=
None
):
def
_load_tasks
(
self
,
tasks
,
vars
=
{},
sudo_vars
=
{},
additional_conditions
=
[],
original_file
=
None
):
''' handle task and handler include statements '''
results
=
[]
...
...
@@ -260,6 +262,15 @@ class Play(object):
if
not
isinstance
(
x
,
dict
):
raise
errors
.
AnsibleError
(
"expecting dict; got:
%
s"
%
x
)
# evaluate sudo vars for current and child tasks
included_sudo_vars
=
{}
for
k
in
[
"sudo"
,
"sudo_user"
]:
if
k
in
x
:
included_sudo_vars
[
k
]
=
x
[
k
]
elif
k
in
sudo_vars
:
included_sudo_vars
[
k
]
=
sudo_vars
[
k
]
x
[
k
]
=
sudo_vars
[
k
]
if
'meta'
in
x
:
if
x
[
'meta'
]
==
'flush_handlers'
:
results
.
append
(
Task
(
self
,
x
))
...
...
@@ -285,7 +296,7 @@ class Play(object):
included_additional_conditions
.
append
(
utils
.
compile_when_to_only_if
(
"
%
s
%
s"
%
(
k
[
5
:],
x
[
k
])))
elif
k
==
'when'
:
included_additional_conditions
.
append
(
utils
.
compile_when_to_only_if
(
"jinja2_compare
%
s"
%
x
[
k
]))
elif
k
in
(
"include"
,
"vars"
,
"only_if"
):
elif
k
in
(
"include"
,
"vars"
,
"only_if"
,
"sudo"
,
"sudo_user"
):
pass
else
:
raise
errors
.
AnsibleError
(
"parse error: task includes cannot be used with other directives:
%
s"
%
k
)
...
...
@@ -307,7 +318,7 @@ class Play(object):
include_file
=
template
(
dirname
,
tokens
[
0
],
mv
)
include_filename
=
utils
.
path_dwim
(
dirname
,
include_file
)
data
=
utils
.
parse_yaml_from_file
(
include_filename
)
results
+=
self
.
_load_tasks
(
data
,
mv
,
included_additional_conditions
,
original_file
=
include_filename
)
results
+=
self
.
_load_tasks
(
data
,
mv
,
included_
sudo_vars
,
included_
additional_conditions
,
original_file
=
include_filename
)
elif
type
(
x
)
==
dict
:
results
.
append
(
Task
(
self
,
x
,
module_vars
=
task_vars
,
additional_conditions
=
additional_conditions
))
else
:
...
...
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