add want_ssh_ansible_host flag to foreman dynamic inventory (#34169)

pull/48758/head
Keith Resar 6 years ago committed by ansibot
parent 0755f16f9a
commit 43affc661b

@ -152,6 +152,12 @@ want_hostcollections = False
# Disabled by default as the change would else not be backward compatible. # Disabled by default as the change would else not be backward compatible.
rich_params = False 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] [cache]
path = . path = .
max_age = 60 max_age = 60

@ -115,6 +115,11 @@ class ForemanInventory(object):
except (ConfigParser.NoOptionError, ConfigParser.NoSectionError): except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
self.want_hostcollections = False 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) # Do we want parameters to be interpreted if possible as JSON? (no by default)
try: try:
self.rich_params = config.getboolean('ansible', 'rich_params') self.rich_params = config.getboolean('ansible', 'rich_params')
@ -434,6 +439,8 @@ class ForemanInventory(object):
'foreman': self.cache[hostname], 'foreman': self.cache[hostname],
'foreman_params': self.params[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: if self.want_facts:
self.inventory['_meta']['hostvars'][hostname]['foreman_facts'] = self.facts[hostname] self.inventory['_meta']['hostvars'][hostname]['foreman_facts'] = self.facts[hostname]

Loading…
Cancel
Save