6d9f7f2337
Without this patch, the set _network_data directive fails when container_networks is not defined, and the whole address lookup fails. This is a problem because, some inventories might not ship container_networks, and rely on default behavior to fallback to ansible_host. This fixes the issue by simplifying the lookup, and relying on jmespath behavior to fallback to data when its not found, reducing the amount of jinja written to find the data. Change-Id: Ib3fce08290f71d1b8682167c722089f52ad7a301
26 lines
1.1 KiB
YAML
26 lines
1.1 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: Set IP to use for {{ network_address }}
|
|
set_fact: "{{ network_address }}={{ hostvars[inventory_hostname] | json_query(query) }}"
|
|
vars:
|
|
query: "{{ is_metal | ternary(metal_query, non_metal_query) }}"
|
|
non_metal_query: "container_networks.{{ network_address }}.address || ansible_host"
|
|
find_bridge: "container_networks.{{ network_address }}.bridge"
|
|
metal_query: "ansible_{{ hostvars[inventory_hostname]|json_query(find_bridge) | replace('-','_') }}.ipv4.address || {{ non_metal_query }}"
|
|
tags:
|
|
- common-address
|
|
- always
|