diff options
author | Michael DeHaan <michael@ansibleworks.com> | 2013-04-27 10:24:26 -0400 |
---|---|---|
committer | Michael DeHaan <michael@ansibleworks.com> | 2013-04-27 10:24:26 -0400 |
commit | aa55268514cb0076b3e63bbf3b5b749333fdd0e7 (patch) | |
tree | e31607a6fb90dcdfc896365efcb29a6c59918cbd /bin/ansible-playbook | |
parent | 515fbd5a17b0fc235b46164009fb370727cad234 (diff) | |
download | ansible-aa55268514cb0076b3e63bbf3b5b749333fdd0e7.tar.gz |
Adds a logfile for ansible playbooks that can be set by the environment or configuration file.
Diffstat (limited to 'bin/ansible-playbook')
-rwxr-xr-x | bin/ansible-playbook | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/bin/ansible-playbook b/bin/ansible-playbook index a241b8e996..79c883fced 100755 --- a/bin/ansible-playbook +++ b/bin/ansible-playbook @@ -28,16 +28,17 @@ from ansible import errors from ansible import callbacks from ansible import utils from ansible.color import ANSIBLE_COLOR, stringc +from ansible.callbacks import display def colorize(lead, num, color): """ Print 'lead' = 'num' in 'color' """ - if num != 0 and ANSIBLE_COLOR: + if num != 0 and ANSIBLE_COLOR and color is not None: return "%s%s%-15s" % (stringc(lead, color), stringc("=", color), stringc(str(num), color)) else: return "%s=%-4s" % (lead, str(num)) -def hostcolor(host, stats): - if ANSIBLE_COLOR: +def hostcolor(host, stats, color=True): + if ANSIBLE_COLOR and color: if stats['failures'] != 0 or stats['unreachable'] != 0: return "%-37s" % stringc(host, 'red') elif stats['changed'] != 0: @@ -180,7 +181,7 @@ def main(args): pb.run() hosts = sorted(pb.stats.processed.keys()) - print callbacks.banner("PLAY RECAP") + display(callbacks.banner("PLAY RECAP")) playbook_cb.on_stats(pb.stats) for h in hosts: @@ -191,16 +192,28 @@ def main(args): if len(failed_hosts) > 0: filename = pb.generate_retry_inventory(failed_hosts) if filename: - print " to retry, use: --limit @%s\n" % filename + display(" to retry, use: --limit @%s\n" % filename) for h in hosts: t = pb.stats.summarize(h) - print "%s : %s %s %s %s" % ( + + display("%s : %s %s %s %s" % ( hostcolor(h, t), colorize('ok', t['ok'], 'green'), colorize('changed', t['changed'], 'yellow'), colorize('unreachable', t['unreachable'], 'red'), - colorize('failed', t['failures'], 'red')) + colorize('failed', t['failures'], 'red')), + screen_only=True + ) + + display("%s : %s %s %s %s" % ( + hostcolor(h, t, False), + colorize('ok', t['ok'], None), + colorize('changed', t['changed'], None), + colorize('unreachable', t['unreachable'], None), + colorize('failed', t['failures'], None)), + log_only=True + ) print "" @@ -208,16 +221,19 @@ def main(args): return 2 except errors.AnsibleError, e: - print >>sys.stderr, "ERROR: %s" % e + display("ERROR: %s" % e, color='red') return 1 return 0 if __name__ == "__main__": + display(" ", log_only=True) + display(" ".join(sys.argv), log_only=True) + display(" ", log_only=True) try: sys.exit(main(sys.argv[1:])) except errors.AnsibleError, e: - print >>sys.stderr, "ERROR: %s" % e + display("ERROR: %s" % e, color='red', stderr=True) sys.exit(1) |