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
a5039eec
Commit
a5039eec
authored
Feb 25, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update reporting on playbook runs.
parent
ed971250
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
66 additions
and
16 deletions
+66
-16
bin/ansible
+2
-2
examples/playbook.yml
+3
-0
lib/ansible/playbook.py
+61
-14
No files found.
bin/ansible
View file @
a5039eec
...
@@ -75,7 +75,7 @@ class Cli(object):
...
@@ -75,7 +75,7 @@ class Cli(object):
host_list
=
options
.
host_list
,
host_list
=
options
.
host_list
,
forks
=
options
.
forks
,
forks
=
options
.
forks
,
pattern
=
options
.
pattern
,
pattern
=
options
.
pattern
,
verbose
=
Fals
e
,
verbose
=
Tru
e
,
)
)
else
:
else
:
return
ansible
.
playbook
.
PlayBook
(
return
ansible
.
playbook
.
PlayBook
(
...
@@ -85,7 +85,7 @@ class Cli(object):
...
@@ -85,7 +85,7 @@ class Cli(object):
remote_pass
=
sshpass
,
remote_pass
=
sshpass
,
host_list
=
options
.
host_list
,
host_list
=
options
.
host_list
,
forks
=
options
.
forks
,
forks
=
options
.
forks
,
verbose
=
False
,
verbose
=
True
)
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
examples/playbook.yml
View file @
a5039eec
...
@@ -14,6 +14,9 @@
...
@@ -14,6 +14,9 @@
notify
:
notify
:
-
restart apache
-
restart apache
-
quack like a duck
-
quack like a duck
-
do
:
-
something that will fail
-
command /bin/false
handlers
:
handlers
:
-
do
:
-
do
:
-
restart apache
-
restart apache
...
...
lib/ansible/playbook.py
View file @
a5039eec
...
@@ -60,6 +60,13 @@ class PlayBook(object):
...
@@ -60,6 +60,13 @@ class PlayBook(object):
self
.
remote_pass
=
remote_pass
self
.
remote_pass
=
remote_pass
self
.
verbose
=
verbose
self
.
verbose
=
verbose
# list of changes/invocations/failure counts per host
self
.
processed
=
{}
self
.
dark
=
{}
self
.
changed
=
{}
self
.
invocations
=
{}
self
.
failures
=
{}
if
type
(
playbook
)
==
str
:
if
type
(
playbook
)
==
str
:
playbook
=
yaml
.
load
(
file
(
playbook
)
.
read
())
playbook
=
yaml
.
load
(
file
(
playbook
)
.
read
())
self
.
playbook
=
playbook
self
.
playbook
=
playbook
...
@@ -69,11 +76,18 @@ class PlayBook(object):
...
@@ -69,11 +76,18 @@ class PlayBook(object):
for
pattern
in
self
.
playbook
:
for
pattern
in
self
.
playbook
:
self
.
_run_pattern
(
pattern
)
self
.
_run_pattern
(
pattern
)
if
self
.
verbose
:
# TODO: return a summary of success & failure counts per node
print
"
\n
"
# TODO: in bin/ancible, ensure return codes are appropriate
results
=
{}
return
"complete"
for
host
in
self
.
processed
.
keys
():
results
[
host
]
=
{
'resources'
:
self
.
invocations
.
get
(
host
,
0
),
'changed'
:
self
.
changed
.
get
(
host
,
0
),
'dark'
:
self
.
dark
.
get
(
host
,
0
),
'failed'
:
self
.
failures
.
get
(
host
,
0
)
}
return
results
def
_get_task_runner
(
self
,
def
_get_task_runner
(
self
,
pattern
=
None
,
pattern
=
None
,
...
@@ -116,10 +130,11 @@ class PlayBook(object):
...
@@ -116,10 +130,11 @@ class PlayBook(object):
module_name
=
tokens
[
0
]
module_name
=
tokens
[
0
]
module_args
=
tokens
[
1
:]
module_args
=
tokens
[
1
:]
namestr
=
"
%
s/
%
s"
%
(
pattern
,
comment
)
if
self
.
verbose
:
if
conditional
:
if
not
conditional
:
namestr
=
"notified/
%
s"
%
namestr
print
"
\n
TASK [
%
s]"
%
(
comment
)
print
"TASK [
%
s]"
%
namestr
else
:
print
"
\n
NOTIFIED [
%
s]"
%
(
comment
)
runner
=
self
.
_get_task_runner
(
runner
=
self
.
_get_task_runner
(
pattern
=
pattern
,
pattern
=
pattern
,
...
@@ -134,15 +149,43 @@ class PlayBook(object):
...
@@ -134,15 +149,43 @@ class PlayBook(object):
ok_hosts
=
contacted
.
keys
()
ok_hosts
=
contacted
.
keys
()
for
host
,
msg
in
dark
.
items
():
for
host
,
msg
in
dark
.
items
():
print
"DARK: [
%
s] =>
%
s"
%
(
host
,
msg
)
self
.
processed
[
host
]
=
1
if
self
.
verbose
:
print
"unreachable: [
%
s] =>
%
s"
%
(
host
,
msg
)
if
not
self
.
dark
.
has_key
(
host
):
self
.
dark
[
host
]
=
1
else
:
self
.
dark
[
host
]
=
self
.
dark
[
host
]
+
1
for
host
,
results
in
contacted
.
items
():
for
host
,
results
in
contacted
.
items
():
self
.
processed
[
host
]
=
1
failed
=
False
if
module_name
==
"command"
:
if
module_name
==
"command"
:
if
results
.
get
(
"rc"
,
0
)
!=
0
:
if
results
.
get
(
"rc"
,
0
)
!=
0
:
print
"FAIL: [
%
s/
%
s] =>
%
s"
%
(
host
,
comment
,
results
)
failed
=
True
elif
results
.
get
(
"failed"
,
0
)
==
1
:
elif
results
.
get
(
"failed"
,
0
)
==
1
:
print
"FAIL: [
%
s/
%
s]"
%
(
host
,
comment
,
results
)
failed
=
True
if
failed
:
if
self
.
verbose
:
print
"failure: [
%
s] =>
%
s"
%
(
host
,
results
)
if
not
self
.
failures
.
has_key
(
host
):
self
.
failures
[
host
]
=
1
else
:
self
.
failures
[
host
]
=
self
.
failures
[
host
]
+
1
else
:
if
self
.
verbose
:
print
"ok: [
%
s]"
%
host
if
not
self
.
invocations
.
has_key
(
host
):
self
.
invocations
[
host
]
=
1
else
:
self
.
invocations
[
host
]
=
self
.
invocations
[
host
]
+
1
if
results
.
get
(
'changed'
,
False
):
if
not
self
.
changed
.
has_key
(
host
):
self
.
changed
[
host
]
=
1
else
:
self
.
changes
[
host
]
=
self
.
changed
[
host
]
+
1
# flag which notify handlers need to be run
# flag which notify handlers need to be run
subtasks
=
task
.
get
(
'notify'
,
[])
subtasks
=
task
.
get
(
'notify'
,
[])
...
@@ -178,6 +221,11 @@ class PlayBook(object):
...
@@ -178,6 +221,11 @@ class PlayBook(object):
tasks
=
pg
[
'tasks'
]
tasks
=
pg
[
'tasks'
]
handlers
=
pg
[
'handlers'
]
handlers
=
pg
[
'handlers'
]
self
.
host_list
=
pg
.
get
(
'hosts'
,
'/etc/ansible/hosts'
)
if
self
.
verbose
:
print
"PLAY: [
%
s] from [
%
s] ********** "
%
(
pattern
,
self
.
host_list
)
for
task
in
tasks
:
for
task
in
tasks
:
self
.
_run_task
(
pattern
=
pattern
,
task
=
task
,
handlers
=
handlers
)
self
.
_run_task
(
pattern
=
pattern
,
task
=
task
,
handlers
=
handlers
)
for
task
in
handlers
:
for
task
in
handlers
:
...
@@ -190,6 +238,5 @@ class PlayBook(object):
...
@@ -190,6 +238,5 @@ class PlayBook(object):
conditional
=
True
conditional
=
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