Skip to content

Commit

Permalink
Inventory: fix logic mistake in loading/retrieving variables for groups
Browse files Browse the repository at this point in the history
  • Loading branch information
srgvg committed Aug 19, 2014
1 parent 47f4dec commit a2cfe87
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions lib/ansible/inventory/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def __init__(self, host_list=C.DEFAULT_HOST_LIST, vault_password=None):

# get host vars from host_vars/ files and vars plugins
for host in self.get_hosts():
host.vars = utils.combine_vars(host.vars, self.get_variables(host.name, vault_password=self._vault_password))
host.vars = utils.combine_vars(host.vars, self.get_host_variables(host.name, vault_password=self._vault_password))


def _match(self, str, pattern_str):
Expand Down Expand Up @@ -429,20 +429,22 @@ def _get_group_variables(self, groupname, vault_password=None):
if updated is not None:
vars = utils.combine_vars(vars, updated)

# get group variables set by Inventory Parsers
vars = utils.combine_vars(vars, group.get_variables())

# Read group_vars/ files
vars = utils.combine_vars(vars, self.get_group_vars(group))

return vars

def get_variables(self, hostname, update_cached=False, vault_password=None):

return self.get_host(hostname).get_variables()

def get_host_variables(self, hostname, update_cached=False, vault_password=None):

if hostname not in self._vars_per_host or update_cached:
self._vars_per_host[hostname] = self._get_variables(hostname, vault_password=vault_password)
self._vars_per_host[hostname] = self._get_host_variables(hostname, vault_password=vault_password)
return self._vars_per_host[hostname]

def _get_variables(self, hostname, vault_password=None):
def _get_host_variables(self, hostname, vault_password=None):

host = self.get_host(hostname)
if host is None:
Expand All @@ -466,9 +468,6 @@ def _get_variables(self, hostname, vault_password=None):
if updated is not None:
vars = utils.combine_vars(vars, updated)

# get host variables set by Inventory Parsers
vars = utils.combine_vars(vars, host.get_variables())

# still need to check InventoryParser per host vars
# which actually means InventoryScript per host,
# which is not performant
Expand Down

0 comments on commit a2cfe87

Please sign in to comment.