diff options
author | Kevin Fenzi <kevin@scrye.com> | 2015-09-10 21:27:13 +0000 |
---|---|---|
committer | Kevin Fenzi <kevin@scrye.com> | 2015-09-10 21:27:13 +0000 |
commit | e0954c308fc6d87b5f004b7b3432ef05dc4f83a2 (patch) | |
tree | 1748477cd80aca48607357410a140d482faf1c9d | |
parent | 253b154476a3e69c9fbd6b155f12af72db6a8d98 (diff) | |
download | ansible-e0954c308fc6d87b5f004b7b3432ef05dc4f83a2.tar.gz ansible-e0954c308fc6d87b5f004b7b3432ef05dc4f83a2.tar.xz ansible-e0954c308fc6d87b5f004b7b3432ef05dc4f83a2.zip |
Add hosts with var set helped script from ticket 4848. Thanks doteast
-rwxr-xr-x | scripts/hosts_with_var_set | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/scripts/hosts_with_var_set b/scripts/hosts_with_var_set new file mode 100755 index 000000000..bb4301c8a --- /dev/null +++ b/scripts/hosts_with_var_set @@ -0,0 +1,44 @@ +#!/usr/bin/python +# doteast; base from skvidal +# dump out the hosts with var=value + +import ansible.inventory +import sys +from optparse import OptionParser + + +parser = OptionParser(version="1.0") +parser.add_option('-i', dest='inventory', default=None, + help="Path to inventory file/dir") +parser.add_option('-o', dest='variable', default=None, + help="variable name to check") + +opts, args = parser.parse_args(sys.argv[1:]) + +if opts.inventory: + inv = ansible.inventory.Inventory(host_list=opts.inventory) +else: + inv = ansible.inventory.Inventory() + +if opts.variable.find("=") == -1: + print "Error -o requires var=value format argument" + sys.exit(-1) + +var_name, value = opts.variable.split('=') + +if value == "": + value="None" + +var_set = [] + +for host in sorted(inv.get_hosts()): + vars = inv.get_variables(host.name) + if vars.has_key(var_name): + if str(vars.get(var_name)).find(value) != -1: + var_set.append(host.name) + +print 'hosts with %s:' % var_name +for host in sorted(var_set): + print host + + |