ea32c3da76
On hosts that do not have any containers (ie. computes) network bridges are not needed and may introduce some unwanted overhead. This configuration was possible until Mitaka, but broke with the dynamic-address-fact.yml tasks in Newton. This change checks if the bridge actually exists and otherwise uses the IP configured in the inventory instead. Change-Id: I23668429a19f00f520ac18c76254e83708778d5a
52 lines
2.2 KiB
YAML
52 lines
2.2 KiB
YAML
---
|
|
# Copyright 2017, Rackspace US, Inc.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
- name: Gather address fact
|
|
set_fact:
|
|
# NOTE(cloudnull):
|
|
# Collect the interface address from hostvars of a target node.
|
|
# Check if the host is running in a container. If not, pull the bridge data from the
|
|
# network interface. If an interface bridge is defined, pull the IP address from the
|
|
# physical network device. If no physical bridge is defined collect the address from
|
|
# the "<INTERFACE>_network_data" variable. If nothing is defined use the
|
|
# "ansible_host" address.
|
|
_lookup_address: >-
|
|
{%- set _network_data = hostvars[inventory_hostname]['container_networks'][network_address] | default({}) -%}
|
|
{%- if is_metal is defined and is_metal | bool -%}
|
|
{%- set _bridge = _network_data['bridge'] | default('no_bridge_defined') | replace('-', '_') -%}
|
|
{%- else -%}
|
|
{%- set _bridge = 'no_bridge_defined' -%}
|
|
{%- endif -%}
|
|
{%- if _bridge != 'no_bridge_defined' and hostvars[inventory_hostname]['ansible_' + _bridge] is defined and hostvars[inventory_hostname]['ansible_' + _bridge]['ipv4'] is defined-%}
|
|
{{ hostvars[inventory_hostname]['ansible_' + _bridge]['ipv4']['address'] }}
|
|
{%- elif _network_data['address'] is defined -%}
|
|
{{ _network_data['address'] }}
|
|
{%- else -%}
|
|
{{ ansible_host }}
|
|
{%- endif -%}
|
|
tags:
|
|
- common-address
|
|
- always
|
|
|
|
# NOTE(cloudnull):
|
|
# This task is not in dict formation because it is
|
|
# dynamically loading facts based on the network_address
|
|
# and the _lookup_address.
|
|
- name: Set address fact
|
|
set_fact: "{{ network_address }}={{ _lookup_address }}"
|
|
tags:
|
|
- common-address
|
|
- always
|