def parse_monitors(monitors):
    """
    Given a list of dictionaries, returns a list of hosts that
    can be used in an ansible inventory. These host lines can include
    host variables as well.

    For example, monitors in this format::

        [
            {"host": "mon0.host", "interface": "eth0"},
            {"host": "mon1.host", "interface": "enp0s8"},
        ]

    Would return the following::

        ["mon0.host monitor_interface=eth0", "mon1.host monitor_interface=enp0s8"]

    Because the API allows for both ``interface`` or ``address`` this utility
    will look for both.  Ideally, only one should be defined, but it is up to
    the client to ensure that the one that is needed is passed to the API.
    """
    hosts = []

    for mon in monitors:
        host = []
        host.append(mon["host"])

        # This is an 'either or' situation. The schema engine does not allow us
        # to play with situations that might have one key or the other. That
        # problem gets solved here by trying to use monitor_interface first and
        # then falling back to its address if defined.
        try:
            host.append("monitor_interface=%s" % mon['interface'])
        except KeyError:
            try:
                host.append("monitor_address=%s" % mon['address'])
            except KeyError:
                # do not append monitor_* and just use the host
                pass

        hosts.append(" ".join(host))

    return hosts