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
5c44ec44
Commit
5c44ec44
authored
May 31, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #441 from jkleint/devel
Properly template list of hosts in playbooks.
parents
6034b5b0
70837469
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
6 deletions
+26
-6
lib/ansible/playbook/play.py
+8
-6
test/TestPlayBook.py
+13
-0
test/hosts_list.yml
+5
-0
No files found.
lib/ansible/playbook/play.py
View file @
5c44ec44
...
...
@@ -37,10 +37,16 @@ class Play(object):
# TODO: more error handling
hosts
=
ds
.
get
(
'hosts'
)
if
hosts
is
None
:
raise
errors
.
AnsibleError
(
'hosts declaration is required'
)
elif
isinstance
(
hosts
,
list
):
hosts
=
';'
.
join
(
hosts
)
hosts
=
utils
.
template
(
hosts
,
playbook
.
extra_vars
,
{})
self
.
_ds
=
ds
self
.
playbook
=
playbook
self
.
hosts
=
ds
.
get
(
'hosts'
,
None
)
self
.
hosts
=
utils
.
template
(
self
.
hosts
,
self
.
playbook
.
extra_vars
,
{})
self
.
hosts
=
hosts
self
.
name
=
ds
.
get
(
'name'
,
self
.
hosts
)
self
.
vars
=
ds
.
get
(
'vars'
,
{})
self
.
vars_files
=
ds
.
get
(
'vars_files'
,
[])
...
...
@@ -56,10 +62,6 @@ class Play(object):
self
.
_tasks
=
self
.
_load_tasks
(
self
.
_ds
,
'tasks'
)
self
.
_handlers
=
self
.
_load_tasks
(
self
.
_ds
,
'handlers'
)
if
self
.
hosts
is
None
:
raise
errors
.
AnsibleError
(
'hosts declaration is required'
)
if
isinstance
(
self
.
hosts
,
list
):
self
.
hosts
=
';'
.
join
(
self
.
hosts
)
if
self
.
sudo_user
!=
'root'
:
self
.
sudo
=
True
...
...
test/TestPlayBook.py
View file @
5c44ec44
...
...
@@ -172,3 +172,16 @@ class TestPlaybook(unittest.TestCase):
print
data
assert
data
.
find
(
"ears"
)
!=
-
1
,
"template success"
def
test_yaml_hosts_list
(
self
):
# Make sure playbooks support hosts: [host1, host2]
# TODO: Actually run the play on more than one host
test_callbacks
=
TestCallbacks
()
playbook
=
ansible
.
playbook
.
PlayBook
(
playbook
=
os
.
path
.
join
(
self
.
test_dir
,
'hosts_list.yml'
),
host_list
=
'test/ansible_hosts'
,
stats
=
ans_callbacks
.
AggregateStats
(),
callbacks
=
test_callbacks
,
runner_callbacks
=
test_callbacks
)
play
=
ansible
.
playbook
.
Play
(
playbook
,
playbook
.
playbook
[
0
])
assert
play
.
hosts
==
';'
.
join
((
'host1'
,
'host2'
,
'host3'
))
test/hosts_list.yml
0 → 100644
View file @
5c44ec44
# Test that playbooks support YAML lists of hosts.
---
-
hosts
:
[
host1
,
host2
,
host3
]
tasks
:
-
action
:
command
true
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