diff options
author | Keith Resar <keithresar@users.noreply.github.com> | 2018-11-15 14:58:34 -0600 |
---|---|---|
committer | ansibot <ansibot@users.noreply.github.com> | 2018-11-15 15:58:34 -0500 |
commit | 43affc661b5cea75b7c75592dab5135ba66f8da1 (patch) | |
tree | f3111faa926539f2cd275e6d81f23ea3c0e566d1 /contrib | |
parent | 0755f16f9a8c80b31da957d447df93c622a8fb77 (diff) | |
download | ansible-43affc661b5cea75b7c75592dab5135ba66f8da1.tar.gz |
add want_ssh_ansible_host flag to foreman dynamic inventory (#34169)
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/inventory/foreman.ini | 6 | ||||
-rwxr-xr-x | contrib/inventory/foreman.py | 7 |
2 files changed, 13 insertions, 0 deletions
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] |