porting to ansible 2.0
This commit is contained in:
parent
85378c82e5
commit
402b6fd8cb
1 changed files with 19 additions and 8 deletions
|
@ -1,5 +1,6 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# skvidal
|
# skvidal
|
||||||
|
# doteast: porting to ansible 2.0
|
||||||
# dump out the hosts marked with 'freezes: true' in their vars
|
# dump out the hosts marked with 'freezes: true' in their vars
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,30 +8,39 @@ import ansible.inventory
|
||||||
import sys
|
import sys
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
|
from ansible.parsing.dataloader import DataLoader
|
||||||
|
from ansible.vars import VariableManager
|
||||||
|
from ansible.inventory import Inventory
|
||||||
|
|
||||||
|
|
||||||
parser = OptionParser(version="1.0")
|
parser = OptionParser(version="1.0")
|
||||||
parser.add_option('-i', dest='inventory', default=None,
|
parser.add_option('-i', dest='inventory', default=None,
|
||||||
help="Path to inventory file/dir")
|
help="Path to inventory file/dir")
|
||||||
opts, args = parser.parse_args(sys.argv[1:])
|
opts, args = parser.parse_args(sys.argv[1:])
|
||||||
|
|
||||||
if opts.inventory:
|
variable_manager = VariableManager()
|
||||||
inv = ansible.inventory.Inventory(host_list=opts.inventory)
|
loader = DataLoader()
|
||||||
else:
|
|
||||||
inv = ansible.inventory.Inventory()
|
|
||||||
|
|
||||||
|
|
||||||
|
if opts.inventory:
|
||||||
|
inv = Inventory(loader=loader,variable_manager=variable_manager, host_list=opts.inventory)
|
||||||
|
else:
|
||||||
|
inv = Inventory(loader=loader,variable_manager=variable_manager)
|
||||||
|
|
||||||
|
variable_manager.set_inventory(inv)
|
||||||
|
|
||||||
frozen = []
|
frozen = []
|
||||||
unfrozen = []
|
unfrozen = []
|
||||||
for host in sorted(inv.get_hosts()):
|
for host in sorted(inv.get_hosts()):
|
||||||
vars = inv.get_variables(host.name)
|
vars = variable_manager.get_vars(loader=loader, host=host)
|
||||||
freezes = vars.get('freezes', None)
|
freezes = vars.get('freezes', None)
|
||||||
|
|
||||||
if freezes:
|
if freezes:
|
||||||
frozen.append(host.name)
|
frozen.append(host.get_name())
|
||||||
elif freezes is None:
|
elif freezes is None:
|
||||||
print 'Error: missing freezes: %s' % host.name
|
print 'Error: missing freezes: %s' % host.get_name()
|
||||||
else:
|
else:
|
||||||
unfrozen.append(host.name)
|
unfrozen.append(host.get_name())
|
||||||
|
|
||||||
print 'freeze:'
|
print 'freeze:'
|
||||||
for host in sorted(frozen):
|
for host in sorted(frozen):
|
||||||
|
@ -40,3 +50,4 @@ for host in sorted(frozen):
|
||||||
print 'do not freeze:'
|
print 'do not freeze:'
|
||||||
for host in sorted(unfrozen):
|
for host in sorted(unfrozen):
|
||||||
print 'NF: ' + host
|
print 'NF: ' + host
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue