only set ansible_host if i have data
This commit is contained in:
parent
68936d0530
commit
fd6302bcb8
1 changed files with 5 additions and 1 deletions
|
@ -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':
|
||||||
|
|
Loading…
Reference in a new issue