mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 14:22:46 +00:00
only set ansible_host if i have data
This commit is contained in:
@@ -137,6 +137,7 @@ class InventoryModule(BaseInventoryPlugin):
|
|||||||
prevkey = pref_k = ''
|
prevkey = pref_k = ''
|
||||||
current_host = None
|
current_host = None
|
||||||
|
|
||||||
|
# needed to possibly set ansible_host
|
||||||
netinfo = data.get('network_info_path', "/VirtualBox/GuestInfo/Net/0/V4/IP")
|
netinfo = data.get('network_info_path', "/VirtualBox/GuestInfo/Net/0/V4/IP")
|
||||||
|
|
||||||
for line in source_data:
|
for line in source_data:
|
||||||
@@ -157,8 +158,11 @@ class InventoryModule(BaseInventoryPlugin):
|
|||||||
if current_host not in hostvars:
|
if current_host not in hostvars:
|
||||||
hostvars[current_host] = {}
|
hostvars[current_host] = {}
|
||||||
self.inventory.add_host(current_host)
|
self.inventory.add_host(current_host)
|
||||||
|
|
||||||
# try to get network info
|
# try to get network info
|
||||||
self.inventory.set_variable(current_host, 'ansible_host', self.query_vbox_data(current_host, netinfo))
|
netdata = self.query_vbox_data(current_host, netinfo)
|
||||||
|
if netdata:
|
||||||
|
self.inventory.set_variable(current_host, 'ansible_host', netdata)
|
||||||
|
|
||||||
# found groups
|
# found groups
|
||||||
elif k == 'Groups':
|
elif k == 'Groups':
|
||||||
|
|||||||
Reference in New Issue
Block a user