ansible/scripts/freezelist

47 lines
1.2 KiB
Text
Raw Permalink Normal View History

#!/usr/bin/python
2014-09-21 16:52:38 +02:00
# skvidal
2016-02-09 18:34:24 +00:00
# doteast: porting to ansible 2.0
# dump out the hosts marked with 'freezes: true' in their vars
import ansible.inventory
import sys
from optparse import OptionParser
2016-02-09 18:34:24 +00:00
from ansible.parsing.dataloader import DataLoader
from ansible.vars.manager import VariableManager
from ansible.inventory.manager import InventoryManager
from ansible import constants as C
2016-02-09 18:34:24 +00:00
2014-09-21 16:52:38 +02:00
parser = OptionParser(version="1.0")
parser.add_option('-i', dest='inventory', default=C.DEFAULT_HOST_LIST,
2014-09-21 16:52:38 +02:00
help="Path to inventory file/dir")
opts, args = parser.parse_args(sys.argv[1:])
2016-02-09 18:34:24 +00:00
loader = DataLoader()
inv = InventoryManager(loader=loader, sources=opts.inventory)
variable_manager = VariableManager(loader=loader, inventory=inv)
2014-09-21 16:52:38 +02:00
frozen = []
unfrozen = []
for host in sorted(inv.get_hosts(), key=lambda host: host.name):
vars = variable_manager.get_vars(host=host)
freezes = vars.get('freezes', None)
2014-09-21 16:52:38 +02:00
if freezes:
2016-02-09 18:34:24 +00:00
frozen.append(host.get_name())
elif freezes is None:
print('Error: missing freezes: %s' % host.get_name())
else:
2016-02-09 18:34:24 +00:00
unfrozen.append(host.get_name())
2014-09-21 16:52:38 +02:00
print('freeze:')
2013-05-14 16:12:01 +00:00
for host in sorted(frozen):
print('F: ' + host)
print('do not freeze:')
2013-05-14 16:12:01 +00:00
for host in sorted(unfrozen):
print('NF: ' + host)