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
e7d0c9f8
Commit
e7d0c9f8
authored
Aug 07, 2015
by
James Cammarata
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Re-add vars to Base and standardize var processing
Fixes #11779
parent
ebfd99e3
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
35 deletions
+33
-35
lib/ansible/playbook/base.py
+28
-2
lib/ansible/playbook/block.py
+1
-1
lib/ansible/playbook/play.py
+0
-27
lib/ansible/playbook/task.py
+3
-4
lib/ansible/plugins/strategies/__init__.py
+1
-1
No files found.
lib/ansible/playbook/base.py
View file @
e7d0c9f8
...
@@ -36,9 +36,8 @@ from ansible.parsing import DataLoader
...
@@ -36,9 +36,8 @@ from ansible.parsing import DataLoader
from
ansible.playbook.attribute
import
Attribute
,
FieldAttribute
from
ansible.playbook.attribute
import
Attribute
,
FieldAttribute
from
ansible.template
import
Templar
from
ansible.template
import
Templar
from
ansible.utils.boolean
import
boolean
from
ansible.utils.boolean
import
boolean
from
ansible.utils.debug
import
debug
from
ansible.utils.debug
import
debug
from
ansible.utils.vars
import
combine_vars
from
ansible.template
import
template
from
ansible.template
import
template
class
Base
:
class
Base
:
...
@@ -48,6 +47,9 @@ class Base:
...
@@ -48,6 +47,9 @@ class Base:
_port
=
FieldAttribute
(
isa
=
'int'
)
_port
=
FieldAttribute
(
isa
=
'int'
)
_remote_user
=
FieldAttribute
(
isa
=
'string'
)
_remote_user
=
FieldAttribute
(
isa
=
'string'
)
# variables
_vars
=
FieldAttribute
(
isa
=
'dict'
,
default
=
dict
())
# flags and misc. settings
# flags and misc. settings
_environment
=
FieldAttribute
(
isa
=
'list'
,
default
=
[])
_environment
=
FieldAttribute
(
isa
=
'list'
,
default
=
[])
_no_log
=
FieldAttribute
(
isa
=
'bool'
,
default
=
False
)
_no_log
=
FieldAttribute
(
isa
=
'bool'
,
default
=
False
)
...
@@ -351,6 +353,30 @@ class Base:
...
@@ -351,6 +353,30 @@ class Base:
# restore the UUID field
# restore the UUID field
setattr
(
self
,
'_uuid'
,
data
.
get
(
'uuid'
))
setattr
(
self
,
'_uuid'
,
data
.
get
(
'uuid'
))
def
_load_vars
(
self
,
attr
,
ds
):
'''
Vars in a play can be specified either as a dictionary directly, or
as a list of dictionaries. If the later, this method will turn the
list into a single dictionary.
'''
try
:
if
isinstance
(
ds
,
dict
):
return
ds
elif
isinstance
(
ds
,
list
):
all_vars
=
dict
()
for
item
in
ds
:
if
not
isinstance
(
item
,
dict
):
raise
ValueError
all_vars
=
combine_vars
(
all_vars
,
item
)
return
all_vars
elif
ds
is
None
:
return
{}
else
:
raise
ValueError
except
ValueError
:
raise
AnsibleParserError
(
"Vars in a
%
s must be specified as a dictionary, or a list of dictionaries"
%
self
.
__class__
.
__name__
,
obj
=
ds
)
def
_extend_value
(
self
,
value
,
new_value
):
def
_extend_value
(
self
,
value
,
new_value
):
'''
'''
Will extend the value given with new_value (and will turn both
Will extend the value given with new_value (and will turn both
...
...
lib/ansible/playbook/block.py
View file @
e7d0c9f8
...
@@ -53,7 +53,7 @@ class Block(Base, Become, Conditional, Taggable):
...
@@ -53,7 +53,7 @@ class Block(Base, Become, Conditional, Taggable):
of a role or task include which does, so return those if present.
of a role or task include which does, so return those if present.
'''
'''
all_vars
=
dict
()
all_vars
=
self
.
vars
.
copy
()
if
self
.
_role
:
if
self
.
_role
:
all_vars
.
update
(
self
.
_role
.
get_vars
(
self
.
_dep_chain
))
all_vars
.
update
(
self
.
_role
.
get_vars
(
self
.
_dep_chain
))
...
...
lib/ansible/playbook/play.py
View file @
e7d0c9f8
...
@@ -32,8 +32,6 @@ from ansible.playbook.role import Role
...
@@ -32,8 +32,6 @@ from ansible.playbook.role import Role
from
ansible.playbook.taggable
import
Taggable
from
ansible.playbook.taggable
import
Taggable
from
ansible.playbook.task
import
Task
from
ansible.playbook.task
import
Task
from
ansible.utils.vars
import
combine_vars
__all__
=
[
'Play'
]
__all__
=
[
'Play'
]
...
@@ -64,7 +62,6 @@ class Play(Base, Taggable, Become):
...
@@ -64,7 +62,6 @@ class Play(Base, Taggable, Become):
_name
=
FieldAttribute
(
isa
=
'string'
,
default
=
''
)
_name
=
FieldAttribute
(
isa
=
'string'
,
default
=
''
)
# Variable Attributes
# Variable Attributes
_vars
=
FieldAttribute
(
isa
=
'dict'
,
default
=
dict
())
_vars_files
=
FieldAttribute
(
isa
=
'list'
,
default
=
[])
_vars_files
=
FieldAttribute
(
isa
=
'list'
,
default
=
[])
_vars_prompt
=
FieldAttribute
(
isa
=
'list'
,
default
=
[])
_vars_prompt
=
FieldAttribute
(
isa
=
'list'
,
default
=
[])
_vault_password
=
FieldAttribute
(
isa
=
'string'
)
_vault_password
=
FieldAttribute
(
isa
=
'string'
)
...
@@ -150,30 +147,6 @@ class Play(Base, Taggable, Become):
...
@@ -150,30 +147,6 @@ class Play(Base, Taggable, Become):
return
ds
return
ds
def
_load_vars
(
self
,
attr
,
ds
):
'''
Vars in a play can be specified either as a dictionary directly, or
as a list of dictionaries. If the later, this method will turn the
list into a single dictionary.
'''
try
:
if
isinstance
(
ds
,
dict
):
return
ds
elif
isinstance
(
ds
,
list
):
all_vars
=
dict
()
for
item
in
ds
:
if
not
isinstance
(
item
,
dict
):
raise
ValueError
all_vars
=
combine_vars
(
all_vars
,
item
)
return
all_vars
elif
ds
is
None
:
return
{}
else
:
raise
ValueError
except
ValueError
:
raise
AnsibleParserError
(
"Vars in a playbook must be specified as a dictionary, or a list of dictionaries"
,
obj
=
ds
)
def
_load_tasks
(
self
,
attr
,
ds
):
def
_load_tasks
(
self
,
attr
,
ds
):
'''
'''
Loads a list of blocks from a list which may be mixed tasks/blocks.
Loads a list of blocks from a list which may be mixed tasks/blocks.
...
...
lib/ansible/playbook/task.py
View file @
e7d0c9f8
...
@@ -78,7 +78,6 @@ class Task(Base, Conditional, Taggable, Become):
...
@@ -78,7 +78,6 @@ class Task(Base, Conditional, Taggable, Become):
_retries
=
FieldAttribute
(
isa
=
'int'
,
default
=
1
)
_retries
=
FieldAttribute
(
isa
=
'int'
,
default
=
1
)
_run_once
=
FieldAttribute
(
isa
=
'bool'
)
_run_once
=
FieldAttribute
(
isa
=
'bool'
)
_until
=
FieldAttribute
(
isa
=
'list'
)
# ?
_until
=
FieldAttribute
(
isa
=
'list'
)
# ?
_vars
=
FieldAttribute
(
isa
=
'dict'
,
default
=
dict
())
def
__init__
(
self
,
block
=
None
,
role
=
None
,
task_include
=
None
):
def
__init__
(
self
,
block
=
None
,
role
=
None
,
task_include
=
None
):
''' constructors a task, without the Task.load classmethod, it will be pretty blank '''
''' constructors a task, without the Task.load classmethod, it will be pretty blank '''
...
@@ -166,9 +165,9 @@ class Task(Base, Conditional, Taggable, Become):
...
@@ -166,9 +165,9 @@ class Task(Base, Conditional, Taggable, Become):
# be adding things to them below (special handling for includes).
# be adding things to them below (special handling for includes).
# When that deprecated feature is removed, this can be too.
# When that deprecated feature is removed, this can be too.
if
'vars'
in
ds
:
if
'vars'
in
ds
:
if
not
isinstance
(
ds
[
'vars'
],
dict
):
# _load_vars is defined in Base, and is used to load a dictionary
raise
AnsibleError
(
"vars specified on a task must be a dictionary (got a
%
s)"
%
type
(
ds
[
'vars'
]),
obj
=
new_ds
)
# or list of dictionaries in a standard way
new_ds
[
'vars'
]
=
ds
.
pop
(
'vars'
)
new_ds
[
'vars'
]
=
self
.
_load_vars
(
None
,
ds
.
pop
(
'vars'
)
)
else
:
else
:
new_ds
[
'vars'
]
=
dict
()
new_ds
[
'vars'
]
=
dict
()
...
...
lib/ansible/plugins/strategies/__init__.py
View file @
e7d0c9f8
...
@@ -412,7 +412,7 @@ class StrategyBase:
...
@@ -412,7 +412,7 @@ class StrategyBase:
# set the vars for this task from those specified as params to the include
# set the vars for this task from those specified as params to the include
for
b
in
block_list
:
for
b
in
block_list
:
b
.
vars
=
included_file
.
_args
.
copy
(
)
b
.
vars
.
update
(
included_file
.
_args
.
copy
()
)
return
block_list
return
block_list
...
...
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