Skip to content

Instantly share code, notes, and snippets.

@PoplarYang
Created September 4, 2019 02:06
Show Gist options
  • Save PoplarYang/95ad58716cb29fbaf1e1b411b8781fc8 to your computer and use it in GitHub Desktop.
Save PoplarYang/95ad58716cb29fbaf1e1b411b8781fc8 to your computer and use it in GitHub Desktop.
def tes(node, inventory):
from ansible.parsing.dataloader import DataLoader
from ansible.vars.manager import VariableManager
from ansible.inventory.manager import InventoryManager
from ansible.vars.hostvars import HostVars
dl = DataLoader()
#dl.load_from_file("vars.yml")
im = InventoryManager(loader=dl, sources=[inventory_dir])
vm = VariableManager(loader=dl, inventory=im)
#host = im.get_host(nodes)
hostvars = HostVars(im, vm, dl)
#vm.set_host_variable(host=host, varname="AAA", value="aaa")
#print(vm.get_vars(host=host))
return hostvars[node]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment