From b2e2f8810067592f9b1de0330b0171eae4ec5256 Mon Sep 17 00:00:00 2001 From: Till Maas Date: Jun 12 2018 15:30:04 +0000 Subject: Match debug inventory to dynamic inventory Create the debug inventory the same way as the live inventory to keep the behavior the same. This fixes #214. --- diff --git a/inventory/standard-inventory-qcow2 b/inventory/standard-inventory-qcow2 index 7c47dbd..d2561f8 100755 --- a/inventory/standard-inventory-qcow2 +++ b/inventory/standard-inventory-qcow2 @@ -16,6 +16,8 @@ import tempfile import time import distutils.util +import yaml + IDENTITY = """ -----BEGIN RSA PRIVATE KEY----- MIIEpQIBAAKCAQEA1DrTSXQRF8isQQfPfK3U+eFC4zBrjur+Iy15kbHUYUeSHf5S @@ -111,6 +113,18 @@ def inv_list(subjects): "_meta": {"hostvars": variables}} +def write_debug_inventory(file_, host_vars): + raw_inventory = {"all": {"children": {"localhost": {"hosts": host_vars}, + "subjects": {"hosts": host_vars}, + } + } + } + with open(file_, "w") as ofile: + inventory = yaml.dump(raw_inventory, default_flow_style=False) + ofile.write(inventory) + return inventory + + def start_qemu(image, cloudinit, log, portrange=(2222, 5555)): for _ in range(10): port = random.randint(*portrange) @@ -228,10 +242,8 @@ def inv_host(image): } # Write out a handy inventory file, for our use and for debugging - args = " ".join(["{0}='{1}'".format(*item) for item in variables.items()]) inventory = os.path.join(directory, "inventory") - with open(inventory, "w") as f: - f.write("[subjects]\nlocalhost {0}\n".format(args)) + write_debug_inventory(inventory, {image: variables}) # Wait for ssh to come up ping = [ @@ -289,10 +301,7 @@ def inv_host(image): return None variables["ansible_python_interpreter"] = ansible_python_interpreter # Update inventory file - args = " ".join(["{0}='{1}'".format(*item) for item in variables.items()]) - inventory = os.path.join(directory, "inventory") - with open(inventory, "w") as f: - f.write("[subjects]\nlocalhost {0}\n".format(args)) + write_debug_inventory(inventory, {image: variables}) return variables # Daemonize and watch the processes