fix: Explicity set ansible_port

Explicitly set ansible_port so it is reset in AWX inventories if the
value changes from set to unset.

Signed-off-by: Felix Matouschek <fmatouschek@redhat.com>
This commit is contained in:
Felix Matouschek
2024-04-03 15:39:42 +02:00
parent 7a6bd72943
commit 9f33a3059c

View File

@@ -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)