diff --git a/plugins/inventory/kubevirt.py b/plugins/inventory/kubevirt.py index d37f0fd..587d7a1 100644 --- a/plugins/inventory/kubevirt.py +++ b/plugins/inventory/kubevirt.py @@ -639,6 +639,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable): Secondary interfaces have priority over a service exposing SSH """ ansible_host = None + ansible_port = None if opts.kube_secondary_dns and opts.network_name is not None: # Set ansible_host to the kubesecondarydns derived host name if enabled # See https://github.com/kubevirt/kubesecondarydns#parameters @@ -654,10 +655,11 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable): port = self.get_port_from_service(service) if host is not None and port is not None: ansible_host = host - self.inventory.set_variable(vmi_name, "ansible_port", port) + ansible_port = port # Default to the IP address of the interface if ansible_host was not set prior if ansible_host is None: ansible_host = ip_address self.inventory.set_variable(vmi_name, "ansible_host", ansible_host) + self.inventory.set_variable(vmi_name, "ansible_port", ansible_port)