diff options
author | doteast <ali.elkhalidi@gmail.com> | 2016-02-09 18:34:24 +0000 |
---|---|---|
committer | doteast <ali.elkhalidi@gmail.com> | 2016-02-09 18:34:24 +0000 |
commit | 402b6fd8cb5ba87c415e192b84160dc8cc942cc6 (patch) | |
tree | 6f3af8d84f35230c0c1b232a87fa75d88b8686aa /scripts | |
parent | 85378c82e50695be7b5247bb157ddeb14becb2e2 (diff) | |
download | ansible-402b6fd8cb5ba87c415e192b84160dc8cc942cc6.tar.gz ansible-402b6fd8cb5ba87c415e192b84160dc8cc942cc6.tar.xz ansible-402b6fd8cb5ba87c415e192b84160dc8cc942cc6.zip |
porting to ansible 2.0
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/freezelist | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/scripts/freezelist b/scripts/freezelist index 1468e525c..bc381a4ec 100755 --- a/scripts/freezelist +++ b/scripts/freezelist @@ -1,5 +1,6 @@ #!/usr/bin/python # skvidal +# doteast: porting to ansible 2.0 # dump out the hosts marked with 'freezes: true' in their vars @@ -7,30 +8,39 @@ import ansible.inventory import sys 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.add_option('-i', dest='inventory', default=None, help="Path to inventory file/dir") opts, args = parser.parse_args(sys.argv[1:]) +variable_manager = VariableManager() +loader = DataLoader() + + if opts.inventory: - inv = ansible.inventory.Inventory(host_list=opts.inventory) + inv = Inventory(loader=loader,variable_manager=variable_manager, host_list=opts.inventory) else: - inv = ansible.inventory.Inventory() + inv = Inventory(loader=loader,variable_manager=variable_manager) +variable_manager.set_inventory(inv) frozen = [] unfrozen = [] 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) if freezes: - frozen.append(host.name) + frozen.append(host.get_name()) elif freezes is None: - print 'Error: missing freezes: %s' % host.name + print 'Error: missing freezes: %s' % host.get_name() else: - unfrozen.append(host.name) + unfrozen.append(host.get_name()) print 'freeze:' for host in sorted(frozen): @@ -40,3 +50,4 @@ for host in sorted(frozen): print 'do not freeze:' for host in sorted(unfrozen): print 'NF: ' + host + |