From 7dc7312a8b2c720255d43b8d058b65491785d503 Mon Sep 17 00:00:00 2001 From: Felix Matouschek Date: Fri, 5 Apr 2024 14:35:44 +0200 Subject: [PATCH] feat: Give secondary interfaces a higher priority over services To give secondary interfaces a higher priority over services the use of services is disabled if a network_name was provided. Signed-off-by: Felix Matouschek --- plugins/inventory/kubevirt.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/plugins/inventory/kubevirt.py b/plugins/inventory/kubevirt.py index 6f48ccf..926c0b3 100644 --- a/plugins/inventory/kubevirt.py +++ b/plugins/inventory/kubevirt.py @@ -110,6 +110,7 @@ options: use_service: description: - Enable the use of services to establish an SSH connection to the VirtualMachine. + - Services are only used if no network_name was provided. type: bool default: True create_groups: @@ -665,10 +666,14 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable): ) if opts.base_domain is not None: ansible_host += f".{opts.base_domain}" - elif opts.use_service and service is not None: + elif opts.use_service and service is not None and opts.network_name is None: # Set ansible_host and ansible_port to the host and port from the LoadBalancer # or NodePort service exposing SSH - node_name = f"{vmi.status.nodeName}.{opts.base_domain}" if opts.append_base_domain else vmi.status.nodeName + node_name = ( + f"{vmi.status.nodeName}.{opts.base_domain}" + if opts.append_base_domain + else vmi.status.nodeName + ) host = self.get_host_from_service(service, node_name) port = self.get_port_from_service(service) if host is not None and port is not None: