Skip to content

Support loading inventory host group direct from CLI #1513

@Fizzadar

Description

@Fizzadar

This was added in ed8196d; there are no docs (fair enough, it's experimental) but I feel like this simplifying use-case of inventory_module.host_group would be beneficial. Consider the following inventory.py contents:

proxmox_hosts = ["pve01", "pve02", "pve03"]

access_points = ["unifi01", "unifi02", "unifi03"]

It would be nice to use pyinfra inventory.proxmox_hosts deploy.py instead of the more verbose and potentially more error prone pyinfra inventory.py deploy.py --limit proxmox_hosts.

Currently the code assumes that this argv syntax always refers to a callable, I think checking if the user parameter is an iterable would be a reasonably simple addition and would enhance UX.

def make_inventory_from_func(
inventory_func: Callable[[], Dict[str, List[HostType]]],
override_data: Optional[Dict[Any, Any]] = None,
):
logger.warning("Loading inventory via import function is in alpha!")
try:
groups = inventory_func()
except Exception as e:
raise CliError(f"Failed to load inventory function: {inventory_func.__name__}: {e}")

Originally posted by @mechanarchy in #959

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions