mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-20 19:13:59 -07:00
Move print statements out of playbook.py and back into CLI so we can simplify playbook operations
independent of output, and can also see all the output nicely grouped together if we want to reformat it or make summaries of statistics.
This commit is contained in:
parent
de3cff8cef
commit
85e0de5bb2
3 changed files with 41 additions and 14 deletions
|
@ -21,11 +21,39 @@
|
|||
import sys
|
||||
import ansible.playbook
|
||||
import ansible.constants as C
|
||||
from ansible.utils import *
|
||||
import getpass
|
||||
from optparse import OptionParser
|
||||
|
||||
#######################################################
|
||||
|
||||
class PlaybookCallbacks(object):
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def set_playbook(self, playbook):
|
||||
self.playbook = playbook
|
||||
|
||||
def on_start(self):
|
||||
print "\n"
|
||||
|
||||
def on_task_start(self, name, is_conditional):
|
||||
print task_start_msg(name, is_conditional)
|
||||
|
||||
def on_unreachable(self, host, msg):
|
||||
print "unreachable: [%s] => %s" % (host, msg)
|
||||
|
||||
def on_failed(self, host, results):
|
||||
print "failed: [%s] => %s\n" % (host, smjson(results))
|
||||
|
||||
def on_ok(self, host):
|
||||
print "ok: [%s]\n" % (host)
|
||||
|
||||
def on_play_start(self, pattern):
|
||||
print "PLAY [%s] ****************************\n" % pattern
|
||||
|
||||
|
||||
def main(args):
|
||||
''' run ansible-playbook operations '''
|
||||
|
||||
|
@ -60,6 +88,7 @@ def main(args):
|
|||
forks=options.forks,
|
||||
verbose=True,
|
||||
remote_pass=sshpass,
|
||||
callbacks=PlaybookCallbacks()
|
||||
)
|
||||
pb.run()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue