Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inventory API groups #1283

Merged
merged 2 commits into from
Oct 10, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/ansible/inventory/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def __init__(self, filename=C.DEFAULT_HOST_LIST):
self.groups = self._parse()

def _parse(self):
all_hosts = {}

groups = {}
self.raw = utils.parse_json(self.data)
Expand All @@ -45,7 +46,9 @@ def _parse(self):
group = groups[group_name] = Group(group_name)
host = None
for hostname in hosts:
host = Host(hostname)
if not hostname in all_hosts:
all_hosts[hostname] = Host(hostname)
host = all_hosts[hostname]
group.add_host(host)
# FIXME: hack shouldn't be needed
all.add_host(host)
Expand Down
10 changes: 10 additions & 0 deletions test/TestInventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,13 @@ def test_hosts_list(self):
actual_hosts = inventory.get_hosts(host_names)
actual_host_names = [host.name for host in actual_hosts]
assert host_names == actual_host_names

def test_script_multiple_groups(self):
inventory = self.script_inventory()
vars = inventory.get_variables('zeus')

print "VARS=%s" % vars

assert vars == {'inventory_hostname': 'zeus',
'inventory_hostname_short': 'zeus',
'group_names': ['greek', 'major-god']}
8 changes: 5 additions & 3 deletions test/inventory_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@
options, args = parser.parse_args()

systems = {
"ungouped": [ "jupiter", "saturn" ],
"ungrouped": [ "jupiter", "saturn" ],
"greek": [ "zeus", "hera", "poseidon" ],
"norse": [ "thor", "odin", "loki" ]
"norse": [ "thor", "odin", "loki" ],
"major-god": [ "zeus", "odin" ],
}

variables = {
"thor": {
"hammer": True
}
},
"zeus": {},
}

if options.list_hosts == True:
Expand Down