mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-27 04:41:26 -07:00
constructed inventory does not use group variables from previous inventory #37397
* Add support for loading invenotry group variables in constructed plugin
This commit is contained in:
parent
06b70f1614
commit
81cfbbbeb9
1 changed files with 3 additions and 2 deletions
|
@ -56,6 +56,7 @@ import os
|
||||||
|
|
||||||
from ansible import constants as C
|
from ansible import constants as C
|
||||||
from ansible.errors import AnsibleParserError
|
from ansible.errors import AnsibleParserError
|
||||||
|
from ansible.inventory.helpers import get_group_vars
|
||||||
from ansible.plugins.cache import FactCache
|
from ansible.plugins.cache import FactCache
|
||||||
from ansible.plugins.inventory import BaseInventoryPlugin, Constructable
|
from ansible.plugins.inventory import BaseInventoryPlugin, Constructable
|
||||||
from ansible.module_utils._text import to_native
|
from ansible.module_utils._text import to_native
|
||||||
|
@ -98,7 +99,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable):
|
||||||
for host in inventory.hosts:
|
for host in inventory.hosts:
|
||||||
|
|
||||||
# get available variables to templar
|
# 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
|
if host in fact_cache: # adds facts if cache is active
|
||||||
hostvars = combine_vars(hostvars, fact_cache[host])
|
hostvars = combine_vars(hostvars, fact_cache[host])
|
||||||
|
|
||||||
|
@ -106,7 +107,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable):
|
||||||
self._set_composite_vars(self.get_option('compose'), hostvars, host, strict=strict)
|
self._set_composite_vars(self.get_option('compose'), hostvars, host, strict=strict)
|
||||||
|
|
||||||
# refetch host vars in case new ones have been created above
|
# 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
|
if host in self._cache: # adds facts if cache is active
|
||||||
hostvars = combine_vars(hostvars, self._cache[host])
|
hostvars = combine_vars(hostvars, self._cache[host])
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue