mirror of
https://opendev.org/openstack/ansible-collections-openstack.git
synced 2026-05-08 06:13:13 +00:00
Adds use_name variable
This commit adds the ability to specify whether the ansible_host and ansible_ssh_host variables should use 'name' inplace of 'interface_ip'. The primary use case for this, is if you want to access hosts using the instance name defined in OpenStack instead of the floating IP. This is usually when using a jump/bastion host. Implements: use_names Change-Id: I809cca0f27f16b37cb9c1c18121f468ccf5c805c
This commit is contained in:
@@ -42,6 +42,13 @@ options:
|
|||||||
- name
|
- name
|
||||||
- uuid
|
- uuid
|
||||||
default: "name"
|
default: "name"
|
||||||
|
use_names:
|
||||||
|
description: |
|
||||||
|
Use the host's 'name' instead of 'interface_ip' for the 'ansible_host' and
|
||||||
|
'ansible_ssh_host' facts. This might be desired when using jump or
|
||||||
|
bastion hosts and the name is the FQDN of the host.
|
||||||
|
type: bool
|
||||||
|
default: 'no'
|
||||||
expand_hostvars:
|
expand_hostvars:
|
||||||
description: |
|
description: |
|
||||||
Run extra commands on each host to fill in additional
|
Run extra commands on each host to fill in additional
|
||||||
@@ -237,6 +244,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
|||||||
expand_hostvars = self._config_data.get('expand_hostvars', False)
|
expand_hostvars = self._config_data.get('expand_hostvars', False)
|
||||||
fail_on_errors = self._config_data.get('fail_on_errors', False)
|
fail_on_errors = self._config_data.get('fail_on_errors', False)
|
||||||
all_projects = self._config_data.get('all_projects', False)
|
all_projects = self._config_data.get('all_projects', False)
|
||||||
|
self.use_names = self._config_data.get('use_names', False)
|
||||||
|
|
||||||
source_data = []
|
source_data = []
|
||||||
try:
|
try:
|
||||||
@@ -363,10 +371,20 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
|||||||
|
|
||||||
def _append_hostvars(self, hostvars, groups, current_host,
|
def _append_hostvars(self, hostvars, groups, current_host,
|
||||||
server, namegroup=False):
|
server, namegroup=False):
|
||||||
hostvars[current_host] = dict(
|
if not self.use_names:
|
||||||
ansible_ssh_host=server['interface_ip'],
|
hostvars[current_host] = dict(
|
||||||
ansible_host=server['interface_ip'],
|
ansible_ssh_host=server['interface_ip'],
|
||||||
openstack=server)
|
ansible_host=server['interface_ip'],
|
||||||
|
openstack=server,
|
||||||
|
)
|
||||||
|
|
||||||
|
if self.use_names:
|
||||||
|
hostvars[current_host] = dict(
|
||||||
|
ansible_ssh_host=server['name'],
|
||||||
|
ansible_host=server['name'],
|
||||||
|
openstack=server,
|
||||||
|
)
|
||||||
|
|
||||||
self.inventory.add_host(current_host)
|
self.inventory.add_host(current_host)
|
||||||
|
|
||||||
if self.get_option('legacy_groups'):
|
if self.get_option('legacy_groups'):
|
||||||
|
|||||||
Reference in New Issue
Block a user