diff --git a/contrib/inventory/foreman.ini b/contrib/inventory/foreman.ini index 055c82cdb4..e3946daf02 100644 --- a/contrib/inventory/foreman.ini +++ b/contrib/inventory/foreman.ini @@ -152,6 +152,12 @@ want_hostcollections = False # Disabled by default as the change would else not be backward compatible. rich_params = False +# Whether to populate the ansible_ssh_host variable to explicitly specify the +# connection target. Only tested with Katello (Red Hat Satellite). +# If the foreman 'ip' fact exists then the ansible_ssh_host varibale is populated +# to permit connections where DNS resolution fails. +want_ansible_ssh_host = False + [cache] path = . max_age = 60 diff --git a/contrib/inventory/foreman.py b/contrib/inventory/foreman.py index 7c431933e0..f51d073b17 100755 --- a/contrib/inventory/foreman.py +++ b/contrib/inventory/foreman.py @@ -115,6 +115,11 @@ class ForemanInventory(object): except (ConfigParser.NoOptionError, ConfigParser.NoSectionError): self.want_hostcollections = False + try: + self.want_ansible_ssh_host = config.getboolean('ansible', 'want_ansible_ssh_host') + except (ConfigParser.NoOptionError, ConfigParser.NoSectionError): + self.want_ansible_ssh_host = False + # Do we want parameters to be interpreted if possible as JSON? (no by default) try: self.rich_params = config.getboolean('ansible', 'rich_params') @@ -434,6 +439,8 @@ class ForemanInventory(object): 'foreman': self.cache[hostname], 'foreman_params': self.params[hostname], } + if self.want_ansible_ssh_host and 'ip' in self.cache[hostname]: + self.inventory['_meta']['hostvars'][hostname]['ansible_ssh_host'] = self.cache[hostname]['ip'] if self.want_facts: self.inventory['_meta']['hostvars'][hostname]['foreman_facts'] = self.facts[hostname]