Exemple #1
0
def get_plugin(entry_point):
    """Returns correct plugin instance for given entry point."""

    plugs = plugins.get_playbook_plugins()
    plugin = plugs.get(entry_point)

    if not plugin:
        raise exceptions.InventoryError("Unknown plugin for {0}", entry_point)

    return plugin()
Exemple #2
0
def get_entrypoint():
    """Returns entry point of the plugin.

    It fetches environment variables to do that. All environment
    variables must be defined.
    """

    entry_point = os.getenv(process.ENV_ENTRY_POINT)

    LOG.debug("Entrypoint: %s", entry_point)

    if not entry_point:
        raise exceptions.InventoryError("Unknown entrypoint")

    return entry_point
Exemple #3
0
def main():
    """Main function."""

    options = get_options()
    LOG.debug("Options are %s", options)

    entry_point = get_entrypoint()
    plugin = get_plugin(entry_point)
    inventory = plugin.get_dynamic_inventory()

    if options.list:
        dumps(inventory)
    elif options.host in inventory["_meta"]["hostvars"]:
        dumps(inventory["_meta"]["hostvars"][options.host])
    else:
        raise exceptions.InventoryError("Cannot find required host {0}".format(
            options.host))

    return os.EX_OK