diff --git a/plugins/inventory/pyrocufflink.py b/plugins/inventory/pyrocufflink.py index 26b778a..82b62f9 100644 --- a/plugins/inventory/pyrocufflink.py +++ b/plugins/inventory/pyrocufflink.py @@ -44,6 +44,12 @@ options: description: Exclude domains running specified operating systems type: list default: [] + exclude_test: + description: Exclude domains whose name implies they are testing machines + type: boolean + default: true + env: + - name: PYROCUFFLINK_EXCLUDE_TEST log_excluded: description: Print a log message about excluded domains, useful for troubleshooting @@ -90,6 +96,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable): dns_domain = self.get_option('dns_domain') exclude_off = cast(bool, self.get_option('exclude_off')) exclude_os = cast(list[str], self.get_option('exclude_os')) + exclude_test = cast(list[str], self.get_option('exclude_test')) log_excluded = cast(bool, self.get_option('log_excluded')) assert self.inventory @@ -117,6 +124,13 @@ class InventoryModule(BaseInventoryPlugin, Constructable): host.os_id, ) continue + if exclude_test and host.is_test_host: + if log_excluded: + log.warning( + 'Excluding libvirt domain %s (test machine)', + host.name, + ) + continue if host.title: inventory_hostname = host.title else: @@ -154,6 +168,10 @@ class Host: def groups(self) -> list[str]: return list(self._groups()) + @functools.cached_property + def is_test_host(self) -> bool: + return self.name.startswith('test-') + @functools.cached_property def libosinfo(self) -> Optional[etree.Element]: try: