Commit ecdeb9d3 authored by Elena Grandi's avatar Elena Grandi

Improve saving of the hosts file

parent 7b796122
......@@ -751,15 +751,23 @@ class SimpleAnsibleInventory():
def add_machine(self, machine: Machine):
if machine.groups:
for g in machine.groups:
if g not in self.inventory['all']['children']:
self.inventory['all']['children'][g] = {
'hosts': {}
if g == 'all':
self.inventory['all']['hosts'][machine.name] = {
'macaddress': machine.mac,
}
self.inventory['all']['children'][g]['hosts'][machine.name] = {
'macaddress': machine.mac,
}
self.inventory['all']['children'][g]['hosts'][
machine.name].update(machine.host_vars)
self.inventory['all']['hosts'][machine.name].update(
machine.host_vars)
else:
if g not in self.inventory['all']['children']:
self.inventory['all']['children'][g] = {
'hosts': {}
}
self.inventory['all']['children'][g]['hosts'][
machine.name] = {
'macaddress': machine.mac,
}
self.inventory['all']['children'][g]['hosts'][
machine.name].update(machine.host_vars)
else:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment