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
79fdc1b6
Commit
79fdc1b6
authored
Feb 25, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Notifable handlers only run when something is changed. Awesome.
parent
de80166b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
65 deletions
+46
-65
TODO.md
+0
-36
examples/playbook.yml
+9
-8
lib/ansible/playbook.py
+37
-21
No files found.
TODO.md
deleted
100644 → 0
View file @
de80166b
TODO list and plans
===================
Playbook TODO:
*
error codes and failure summaries
*
handle 'changed' attributes
*
fail nodes on errors, i.e. remove from host list, rather than continuing to pound them
*
further improve output
*
more conditional capability (if statement) (?)
*
very good logging
Command module:
*
magic to pull async & timeout options off of the command line and not feed them
to the app we're executing
General:
*
better logging
*
async options
*
modules for users, groups, and files, using puppet style ensure mechanics
*
think about how to build idempotency (aka Puppet-style 'creates') around command module?
Bonus utilities:
*
ansible-inventory - gathering fact/hw info, storing in git, adding RSS
*
ansible-slurp - recursively rsync file trees for each host
*
maybe it's own fact engine, not required, that also feeds from facter
Not so interested really, but maybe:
*
list available modules from command line
*
add/remove/list hosts from the command line
*
filter exclusion (run this only if fact is true/false)
-- should be doable with playbooks (i.e. not neccessary)
examples/playbook.yml
View file @
79fdc1b6
...
@@ -6,17 +6,18 @@
...
@@ -6,17 +6,18 @@
-
do
:
-
do
:
-
copy a file
-
copy a file
-
copy /srv/a /srv/b
-
copy /srv/a /srv/b
notify
:
-
restart apache
-
do
:
-
do
:
-
template from local file template.j2 to remote location /srv/file.out
-
template from local file template.j2 to remote location /srv/file.out
-
template /srv/template.j2 /srv/file.out
-
template /srv/template.j2 /srv/file.out
-
do
:
notify
:
-
update
apache
-
restart
apache
-
command /usr/bin/yum update apache
-
quack like a duck
onchange
:
handlers
:
-
do
:
-
do
:
-
restart apache
-
restart apache
-
command /sbin/service
apache
restart
-
command /sbin/service
httpd
restart
-
do
:
-
do
:
-
run bin
false
-
quack like a duck
-
command /bin/false
-
command /bin/true
lib/ansible/playbook.py
View file @
79fdc1b6
...
@@ -101,7 +101,7 @@ class PlayBook(object):
...
@@ -101,7 +101,7 @@ class PlayBook(object):
timeout
=
self
.
timeout
timeout
=
self
.
timeout
)
)
def
_run_task
(
self
,
pattern
,
task
,
host_list
=
None
,
conditional
=
False
):
def
_run_task
(
self
,
pattern
=
None
,
task
=
None
,
host_list
=
None
,
handlers
=
None
,
conditional
=
False
):
'''
'''
run a single task in the playbook and
run a single task in the playbook and
recursively run any subtasks.
recursively run any subtasks.
...
@@ -118,7 +118,7 @@ class PlayBook(object):
...
@@ -118,7 +118,7 @@ class PlayBook(object):
namestr
=
"
%
s/
%
s"
%
(
pattern
,
comment
)
namestr
=
"
%
s/
%
s"
%
(
pattern
,
comment
)
if
conditional
:
if
conditional
:
namestr
=
"
subset
/
%
s"
%
namestr
namestr
=
"
notified
/
%
s"
%
namestr
print
"TASK [
%
s]"
%
namestr
print
"TASK [
%
s]"
%
namestr
runner
=
self
.
_get_task_runner
(
runner
=
self
.
_get_task_runner
(
...
@@ -130,15 +130,7 @@ class PlayBook(object):
...
@@ -130,15 +130,7 @@ class PlayBook(object):
results
=
runner
.
run
()
results
=
runner
.
run
()
dark
=
results
.
get
(
"dark"
,
[])
dark
=
results
.
get
(
"dark"
,
[])
contacted
=
results
.
get
(
"contacted"
,
[])
contacted
=
results
.
get
(
"contacted"
,
[])
# TODO: filter based on values that indicate
# they have changed events to emulate Puppet
# 'notify' behavior, super easy -- just
# a list comprehension -- but we need complaint
# modules first
ok_hosts
=
contacted
.
keys
()
ok_hosts
=
contacted
.
keys
()
for
host
,
msg
in
dark
.
items
():
for
host
,
msg
in
dark
.
items
():
...
@@ -152,27 +144,51 @@ class PlayBook(object):
...
@@ -152,27 +144,51 @@ class PlayBook(object):
print
"FAIL: [
%
s/
%
s]"
%
(
host
,
comment
,
results
)
print
"FAIL: [
%
s/
%
s]"
%
(
host
,
comment
,
results
)
subtasks
=
task
.
get
(
'onchange'
,
[])
# flag which notify handlers need to be run
subtasks
=
task
.
get
(
'notify'
,
[])
if
len
(
subtasks
)
>
0
:
if
len
(
subtasks
)
>
0
:
for
subtask
in
subtasks
:
for
host
,
results
in
contacted
.
items
():
self
.
_run_task
(
pattern
,
subtask
,
ok_hosts
,
conditional
=
True
)
if
results
.
get
(
'changed'
,
False
):
for
subtask
in
subtasks
:
self
.
_flag_handler
(
handlers
,
subtask
,
host
)
# TODO: if a host fails in task 1, add it to an excludes
# TODO: if a host fails in any task, remove it from
# list such that no other tasks in the list ever execute
# the host list immediately
# unlike Puppet, do not allow partial failure of the tree
# and continuing as far as possible. Fail fast.
def
_flag_handler
(
self
,
handlers
,
match_name
,
host
):
'''
if a task has any notify elements, flag handlers for run
at end of execution cycle for hosts that have indicated
changes have been made
'''
for
x
in
handlers
:
attribs
=
x
[
"do"
]
name
=
attribs
[
0
]
if
match_name
==
name
:
if
not
x
.
has_key
(
"run"
):
x
[
'run'
]
=
[]
x
[
'run'
]
.
append
(
host
)
def
_run_pattern
(
self
,
pg
):
def
_run_pattern
(
self
,
pg
):
'''
'''
run a list of tasks for a given pattern, in order
run a list of tasks for a given pattern, in order
'''
'''
pattern
=
pg
[
'pattern'
]
pattern
=
pg
[
'pattern'
]
tasks
=
pg
[
'tasks'
]
tasks
=
pg
[
'tasks'
]
for
task
in
tasks
:
handlers
=
pg
[
'handlers'
]
self
.
_run_task
(
pattern
,
task
)
for
task
in
tasks
:
self
.
_run_task
(
pattern
=
pattern
,
task
=
task
,
handlers
=
handlers
)
for
task
in
handlers
:
if
type
(
task
.
get
(
"run"
,
None
))
==
list
:
self
.
_run_task
(
pattern
=
pattern
,
task
=
task
,
handlers
=
handlers
,
host_list
=
task
.
get
(
'run'
,[]),
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