# Pastebin A1AZHhhA - 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 "_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]['ipv4'] is defined-%} {{ hostvars[inventory_hostname]['ansible_' + _bridge]['ipv4']['address'] }} {%- elif _network_data['address'] is defined -%} {{ _network_data['address'] }} {%- else -%} {{ ansible_ssh_host }} {%- endif -%} tags: - always