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
279b5965
Commit
279b5965
authored
Jul 14, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Much streamlining around setup steps in playbooks, now only run setup once per play.
parent
931f9f1a
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
24 additions
and
36 deletions
+24
-36
CHANGELOG.md
+1
-0
examples/playbooks/templates/foo.j2
+6
-0
lib/ansible/callbacks.py
+2
-5
lib/ansible/playbook/__init__.py
+11
-19
test/TestPlayBook.py
+3
-9
test/TestRunner.py
+1
-3
No files found.
CHANGELOG.md
View file @
279b5965
...
...
@@ -20,6 +20,7 @@ Ansible Changes By Release
*
modules now consistently all take yes/no for boolean parameters (some accepted true/false)
*
in YAML inventory, hosts can list their groups in inverted order now also (see tests/yaml_hosts)
*
setup module no longer saves to disk, template module now only used in playbooks
*
setup module no longer needs to run twice per playbook
0.
5 "Amsterdam" ------- July 04, 2012
...
...
examples/playbooks/templates/foo.j2
View file @
279b5965
# This is a very simple Jinja2 template representing an imaginary configuration file
# for an imaginary app.
# this is an example of loading a fact from the setup module
system={{ ansible_system }}
# here is a variable that could be set in a playbook or inventory file
http_port={{ http_port }}
lib/ansible/callbacks.py
View file @
279b5965
...
...
@@ -247,12 +247,9 @@ class PlaybookCallbacks(object):
return
getpass
.
getpass
(
msg
)
return
raw_input
(
msg
)
def
on_setup
_primary
(
self
):
print
banner
(
"
SETUP PHASE
"
)
def
on_setup
(
self
):
print
banner
(
"
GATHERING FACTS
"
)
def
on_setup_secondary
(
self
):
print
banner
(
"VARIABLE IMPORT PHASE"
)
def
on_import_for_host
(
self
,
host
,
imported_file
):
print
"
%
s: importing
%
s"
%
(
host
,
imported_file
)
...
...
lib/ansible/playbook/__init__.py
View file @
279b5965
...
...
@@ -270,19 +270,13 @@ class PlayBook(object):
# *****************************************************
def
_do_setup_step
(
self
,
play
,
vars_files
=
None
):
def
_do_setup_step
(
self
,
play
):
'''
push variables down to the systems and get variables+facts back up
'''
'''
get facts from the remote system
'''
# this enables conditional includes like $facter_os.yml and is only done
# after the original pass when we have that data.
#
setup_args
=
{}
if
vars_files
is
not
None
:
self
.
callbacks
.
on_setup_secondary
()
play
.
update_vars_files
(
self
.
inventory
.
list_hosts
(
play
.
hosts
))
else
:
self
.
callbacks
.
on_setup_primary
()
self
.
callbacks
.
on_setup
()
host_list
=
[
h
for
h
in
self
.
inventory
.
list_hosts
(
play
.
hosts
)
if
not
(
h
in
self
.
stats
.
failures
or
h
in
self
.
stats
.
dark
)
]
...
...
@@ -291,7 +285,7 @@ class PlayBook(object):
# push any variables down to the system
setup_results
=
ansible
.
runner
.
Runner
(
pattern
=
play
.
hosts
,
module_name
=
'setup'
,
module_args
=
play
.
var
s
,
inventory
=
self
.
inventory
,
pattern
=
play
.
hosts
,
module_name
=
'setup'
,
module_args
=
setup_arg
s
,
inventory
=
self
.
inventory
,
forks
=
self
.
forks
,
module_path
=
self
.
module_path
,
timeout
=
self
.
timeout
,
remote_user
=
play
.
remote_user
,
remote_pass
=
self
.
remote_pass
,
remote_port
=
play
.
remote_port
,
private_key_file
=
self
.
private_key_file
,
setup_cache
=
self
.
SETUP_CACHE
,
callbacks
=
self
.
runner_callbacks
,
sudo
=
play
.
sudo
,
sudo_user
=
play
.
sudo_user
,
...
...
@@ -304,11 +298,9 @@ class PlayBook(object):
# now for each result, load into the setup cache so we can
# let runner template out future commands
setup_ok
=
setup_results
.
get
(
'contacted'
,
{})
if
vars_files
is
None
:
# first pass only or we'll erase good work
for
(
host
,
result
)
in
setup_ok
.
iteritems
():
if
'ansible_facts'
in
result
:
self
.
SETUP_CACHE
[
host
]
=
result
[
'ansible_facts'
]
for
(
host
,
result
)
in
setup_ok
.
iteritems
():
if
'ansible_facts'
in
result
:
self
.
SETUP_CACHE
[
host
]
=
result
[
'ansible_facts'
]
return
setup_results
# *****************************************************
...
...
@@ -321,12 +313,12 @@ class PlayBook(object):
self
.
callbacks
.
on_play_start
(
play
.
name
)
#
push any variables down to the system # and get facts/ohai/other data back up
rc
=
self
.
_do_setup_step
(
play
)
# pattern, vars, user, port, sudo, sudo_user, transport, None)
#
get facts from system
rc
=
self
.
_do_setup_step
(
play
)
# now with that data, handle contentional variable file imports!
if
play
.
vars_files
and
len
(
play
.
vars_files
)
>
0
:
rc
=
self
.
_do_setup_step
(
play
,
play
.
vars_files
)
play
.
update_vars_files
(
self
.
inventory
.
list_hosts
(
play
.
hosts
)
)
for
task
in
play
.
tasks
():
...
...
test/TestPlayBook.py
View file @
279b5965
...
...
@@ -30,12 +30,9 @@ class TestCallbacks(object):
def
on_start
(
self
):
EVENTS
.
append
(
'start'
)
def
on_setup
_primary
(
self
):
def
on_setup
(
self
):
EVENTS
.
append
([
'primary_setup'
])
def
on_setup_secondary
(
self
):
EVENTS
.
append
([
'secondary_setup'
])
def
on_skipped
(
self
,
host
):
EVENTS
.
append
([
'skipped'
,
[
host
]])
...
...
@@ -86,12 +83,9 @@ class TestCallbacks(object):
def
on_unreachable
(
self
,
host
,
msg
):
EVENTS
.
append
([
'failed/dark'
,
[
host
,
msg
]])
def
on_setup
_primary
(
self
):
def
on_setup
(
self
):
pass
def
on_setup_secondary
(
self
):
pass
def
on_no_hosts
(
self
):
pass
...
...
@@ -158,7 +152,7 @@ class TestPlaybook(unittest.TestCase):
"127.0.0.2"
:
{
"changed"
:
9
,
"failures"
:
0
,
"ok"
:
1
2
,
"ok"
:
1
1
,
"skipped"
:
1
,
"unreachable"
:
0
}
...
...
test/TestRunner.py
View file @
279b5965
...
...
@@ -194,14 +194,13 @@ class TestRunner(unittest.TestCase):
def
test_service
(
self
):
# TODO: tests for the service module
pass
def
test_assemble
(
self
):
input
=
self
.
_get_test_file
(
'assemble.d'
)
metadata
=
self
.
_get_test_file
(
'metadata.json'
)
output
=
self
.
_get_stage_file
(
'sample.out'
)
result
=
self
.
_run
(
'assemble'
,
[
"src=
%
s"
%
input
,
"dest=
%
s"
%
output
,
"metadata=
%
s"
%
metadata
])
assert
os
.
path
.
exists
(
output
)
out
=
file
(
output
)
.
read
()
...
...
@@ -214,7 +213,6 @@ class TestRunner(unittest.TestCase):
result
=
self
.
_run
(
'assemble'
,
[
"src=
%
s"
%
input
,
"dest=
%
s"
%
output
,
"metadata=
%
s"
%
metadata
])
assert
result
[
'changed'
]
==
False
...
...
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