Skip to content

Commit

Permalink
constructed inventory does not use group variables from previous inve…
Browse files Browse the repository at this point in the history
…ntory ansible#37397

* Add support for loading invenotry group variables in constructed plugin
  • Loading branch information
lufik authored and bcoca committed Mar 20, 2018
1 parent 06b70f1 commit 81cfbbb
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/ansible/plugins/inventory/constructed.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@

from ansible import constants as C
from ansible.errors import AnsibleParserError
from ansible.inventory.helpers import get_group_vars
from ansible.plugins.cache import FactCache
from ansible.plugins.inventory import BaseInventoryPlugin, Constructable
from ansible.module_utils._text import to_native
Expand Down Expand Up @@ -98,15 +99,15 @@ def parse(self, inventory, loader, path, cache=False):
for host in inventory.hosts:

# get available variables to templar
hostvars = inventory.hosts[host].get_vars()
hostvars = combine_vars(get_group_vars(inventory.hosts[host].get_groups()), inventory.hosts[host].get_vars())
if host in fact_cache: # adds facts if cache is active
hostvars = combine_vars(hostvars, fact_cache[host])

# create composite vars
self._set_composite_vars(self.get_option('compose'), hostvars, host, strict=strict)

# refetch host vars in case new ones have been created above
hostvars = inventory.hosts[host].get_vars()
hostvars = combine_vars(get_group_vars(inventory.hosts[host].get_groups()), inventory.hosts[host].get_vars())
if host in self._cache: # adds facts if cache is active
hostvars = combine_vars(hostvars, self._cache[host])

Expand Down

0 comments on commit 81cfbbb

Please sign in to comment.