summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorSeth Vidal <skvidal@fedoraproject.org>2013-06-10 23:51:20 +0000
committerSeth Vidal <skvidal@fedoraproject.org>2013-06-10 23:51:20 +0000
commitf31b17c3c9f557e61e8b53bda6ad834de3d2bbc1 (patch)
tree736007183a38d346573d28ab5fe2d395715c423b /scripts
parentc602fa34da34c96b767ce4830aeadbc536fe1211 (diff)
downloadansible-f31b17c3c9f557e61e8b53bda6ad834de3d2bbc1.tar.gz
ansible-f31b17c3c9f557e61e8b53bda6ad834de3d2bbc1.tar.xz
ansible-f31b17c3c9f557e61e8b53bda6ad834de3d2bbc1.zip
add needs-update
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/needs-updates85
1 files changed, 85 insertions, 0 deletions
diff --git a/scripts/needs-updates b/scripts/needs-updates
new file mode 100755
index 000000000..a03fc0b13
--- /dev/null
+++ b/scripts/needs-updates
@@ -0,0 +1,85 @@
+#!/usr/bin/env python
+
+# (c) 2012, Red Hat, Inc
+# Seth Vidal <skvidal at fedoraproject.org>
+#
+#
+########################################################
+
+import sys
+import getpass
+
+import ansible.runner
+import ansible.constants as C
+from ansible import utils
+from ansible import callbacks
+
+########################################################
+
+def main(args):
+
+ # simple parser
+ parser = utils.base_parser(constants=C, runas_opts=True, async_opts=False,
+ output_opts=True, connect_opts=True, usage='ans-command [options]')
+ parser.add_option('--host', dest='hostlist', action='append',
+ help="hosts to contact, defaults to all in your inventory", default=[])
+ options, args = parser.parse_args(args)
+ options.module_name = 'command'
+
+ # no hosts specified? Run against all of them
+ if not options.hostlist:
+ options.pattern = 'all'
+ else:
+ options.pattern = ';'.join(options.hostlist)
+
+ # setup the cli call back so we can use the simple output handling
+ # our callbacks for easy terminal formatting
+
+ mycallback = callbacks.DefaultRunnerCallbacks()
+ mycallback.options = options
+
+ runner = ansible.runner.Runner(
+ module_name=options.module_name, module_path=options.module_path,
+ module_args=options.module_args,
+ remote_user=options.remote_user,
+ host_list=options.inventory, timeout=options.timeout,
+ forks=options.forks,
+ pattern=options.pattern,
+ callbacks=mycallback, sudo=options.sudo,
+ transport=options.connection
+ )
+
+ needsupdate = []
+ results = runner.run()
+ for (host,d) in results['contacted'].items():
+ answer = d.get('rc', '0')
+ if answer == 100:
+ needsupdate.append(host)
+ elif answer == 0:
+ pass
+ else:
+ if d.get('failed', False):
+ err = d.get('stderr', '').strip()
+ if err:
+ print >> sys.stderr, 'Error: %s said %s' % (host, err)
+ msg = d.get('msg', '').strip()
+ if msg:
+ print >> sys.stderr, 'Error: %s said %s' % (host, msg)
+
+ for host in results['dark']:
+ print >> sys.stderr, 'Error: Could not reach: %s' % host
+
+ for host in sorted(needsupdate):
+ print host
+
+
+
+
+if __name__ == '__main__':
+ try:
+ main(sys.argv)
+ except Exception, e:
+ # Generic handler for ansible specific errors
+ print "ERROR: %s" % str(e)
+ sys.exit(1)
+