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
8a433ecb
Commit
8a433ecb
authored
Apr 19, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'align-vars-syntax' of
https://github.com/jhoekx/ansible
into jhoekx-align-vars-syntax
parents
d4a5c4ae
cdb8213d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
9 deletions
+26
-9
lib/ansible/inventory.py
+10
-5
lib/ansible/playbook.py
+11
-1
test/TestInventory.py
+2
-2
test/yaml_hosts
+3
-1
No files found.
lib/ansible/inventory.py
View file @
8a433ecb
...
...
@@ -216,11 +216,16 @@ class Inventory(object):
def
_parse_yaml_host
(
self
,
item
,
variables
=
[]):
def
set_variables
(
host
,
variables
):
for
variable
in
variables
:
if
len
(
variable
)
!=
1
:
raise
errors
.
AnsibleError
(
"Only one item expected in
%
s"
%
(
variable
))
k
,
v
=
variable
.
items
()[
0
]
self
.
_set_variable
(
host
,
k
,
v
)
if
type
(
variables
)
==
list
:
for
variable
in
variables
:
if
len
(
variable
)
!=
1
:
raise
errors
.
AnsibleError
(
"Only one item expected in
%
s"
%
(
variable
))
k
,
v
=
variable
.
items
()[
0
]
self
.
_set_variable
(
host
,
k
,
v
)
elif
type
(
variables
)
==
dict
:
for
k
,
v
in
variables
.
iteritems
():
self
.
_set_variable
(
host
,
k
,
v
)
if
type
(
item
)
in
[
str
,
unicode
]:
set_variables
(
item
,
variables
)
...
...
lib/ansible/playbook.py
View file @
8a433ecb
...
...
@@ -118,8 +118,18 @@ class PlayBook(object):
if
play
.
get
(
'vars'
)
is
None
:
play
[
'vars'
]
=
{}
vars
=
play
[
'vars'
]
if
type
(
vars
)
!=
dict
:
if
type
(
vars
)
not
in
[
dict
,
list
]
:
raise
errors
.
AnsibleError
(
"'vars' section must contain only key/value pairs"
)
# translate a list of vars into a dict
if
type
(
vars
)
==
list
:
varlist
=
vars
vars
=
{}
for
item
in
varlist
:
k
,
v
=
item
.
items
()[
0
]
vars
[
k
]
=
v
play
[
'vars'
]
=
vars
vars_prompt
=
play
.
get
(
'vars_prompt'
,
{})
if
type
(
vars_prompt
)
!=
dict
:
raise
errors
.
AnsibleError
(
"'vars_prompt' section must contain only key/value pairs"
)
...
...
test/TestInventory.py
View file @
8a433ecb
...
...
@@ -220,13 +220,13 @@ class TestInventory(unittest.TestCase):
inventory
=
self
.
yaml_inventory
()
vars
=
inventory
.
get_variables
(
'saturn'
)
assert
vars
==
{
"moon"
:
"titan"
}
assert
vars
==
{
"moon"
:
"titan"
,
"moon2"
:
"enceladus"
}
def
test_yaml_port
(
self
):
inventory
=
self
.
yaml_inventory
()
vars
=
inventory
.
get_variables
(
'hera'
)
assert
vars
==
{
'ansible_ssh_port'
:
3000
}
assert
vars
==
{
'ansible_ssh_port'
:
3000
,
'ntp_server'
:
'olympus.example.com'
}
### Test Runner class method
...
...
test/yaml_hosts
View file @
8a433ecb
...
...
@@ -3,7 +3,8 @@
- jupiter
- host: saturn
vars:
- moon: titan
moon: titan
moon2: enceladus
- zeus
...
...
@@ -14,6 +15,7 @@
- poseidon
vars:
- ansible_ssh_port: 3000
- ntp_server: olympus.example.com
- group: norse
hosts:
...
...
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