From a5af649a7320b6a6adaa888817baa5088bbee5d2 Mon Sep 17 00:00:00 2001 From: Jim Ladd Date: Sat, 15 Feb 2020 02:05:08 -0800 Subject: [PATCH] foreman: ansible_ssh_host should consider ip, ipv4, ipv6 (#67401) --- lib/ansible/plugins/inventory/foreman.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/ansible/plugins/inventory/foreman.py b/lib/ansible/plugins/inventory/foreman.py index c13e89d9460..43073f81ad4 100644 --- a/lib/ansible/plugins/inventory/foreman.py +++ b/lib/ansible/plugins/inventory/foreman.py @@ -263,12 +263,14 @@ class InventoryModule(BaseInventoryPlugin, Cacheable, Constructable): # put ansible_ssh_host as hostvar if self.get_option('want_ansible_ssh_host'): - if host.get('ip'): - try: - self.inventory.set_variable(host_name, 'ansible_ssh_host', host['ip']) - except ValueError as e: - self.display.warning("Could not set hostvar ansible_ssh_host to '%s' for the '%s' host, skipping: %s" % - (host['ip'], host_name, to_text(e))) + for key in ('ip', 'ipv4', 'ipv6'): + if host.get(key): + try: + self.inventory.set_variable(host_name, 'ansible_ssh_host', host[key]) + break + except ValueError as e: + self.display.warning("Could not set hostvar ansible_ssh_host to '%s' for the '%s' host, skipping: %s" % + (host[key], host_name, to_text(e))) strict = self.get_option('strict')