Skip to content

Commit

Permalink
unify interface lookups
Browse files Browse the repository at this point in the history
The playbooks were running a bunch of common tasks that could be
simplified and unified into a single common_task include. This PR moves
the interface look into a single place and cleans up the duplicate code
within the cinder, neutron, and nova playbooks.

Change-Id: I46f2812670ea17b9ff28ef6f054d82fd6dccc999
Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
  • Loading branch information
cloudnull authored and Jesse Pretorius (odyssey4me) committed Feb 27, 2017
1 parent 945a785 commit 4c04c68
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 72 deletions.
49 changes: 49 additions & 0 deletions playbooks/common-tasks/dynamic-address-fact.yml
@@ -0,0 +1,49 @@
---
# 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' -%}
{{ hostvars[inventory_hostname]['ansible_' + _bridge]['ipv4']['address'] }}
{%- elif _network_data['address'] is defined -%}
{{ _network_data['address'] }}
{%- else -%}
{{ ansible_host }}
{%- endif -%}
tags:
- 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:
- always
27 changes: 3 additions & 24 deletions playbooks/os-cinder-install.yml
Expand Up @@ -19,30 +19,9 @@
max_fail_percentage: 20
user: root
pre_tasks:
- name: Set the cinder storage address
set_fact:
# NOTE(cloudnull):
# Collect the storage address interface data from the host vars of the target node then
# Check if the host is running in a container. If not, pull the bridge data from the
# storage network. If a storage_bridge is defined pull the IP address from the physical
# network device. If no physical bridge is defined collect the storage address from the
# "storage_network_data" variable. If nothing is defined use the "ansible_host" address.
storage_address: >-
{%- set storage_network_data = hostvars[inventory_hostname]['container_networks']['storage_address'] | default({}) -%}
{%- if is_metal is defined and is_metal | bool -%}
{%- set storage_bridge = storage_network_data['bridge'] | default('no_bridge_defined') | replace('-', '_') -%}
{%- else -%}
{%- set storage_bridge = 'no_bridge_defined' -%}
{%- endif -%}
{%- if storage_bridge != 'no_bridge_defined' -%}
{{ hostvars[inventory_hostname]['ansible_' + storage_bridge]['ipv4']['address'] }}
{%- elif storage_network_data['address'] is defined -%}
{{ storage_network_data['address'] }}
{%- else -%}
{{ ansible_host }}
{%- endif -%}
tags:
- always
- include: common-tasks/dynamic-address-fact.yml
vars:
network_address: "storage_address"
- include: common-tasks/os-lxc-container-setup.yml
static: no
vars:
Expand Down
20 changes: 4 additions & 16 deletions playbooks/os-neutron-install.yml
Expand Up @@ -30,6 +30,9 @@
max_fail_percentage: 20
user: root
pre_tasks:
- include: common-tasks/dynamic-address-fact.yml
vars:
network_address: "tunnel_address"
- include: common-tasks/os-lxc-container-setup.yml
# This config is specific to Ubuntu
vars:
Expand Down Expand Up @@ -114,28 +117,13 @@
- name: Set provider network fact(s)
set_fact:
_provider_networks: "{{ pndata }}"
_overlay_network: "{{ container_networks.tunnel_address|default({}) }}"
tags:
- always
- name: set local_ip fact (is_metal)
set_fact:
_local_ip: "{{ hostvars[inventory_hostname]['ansible_' + _overlay_network.bridge|default(ansible_default_ipv4['interface'])|replace('-', '_')]['ipv4']['address']|default(ansible_host) }}"
when:
- is_metal | bool
tags:
- always
- name: set local_ip fact (container)
set_fact:
_local_ip: "{{ _overlay_network.address|default(ansible_host) }}"
when:
- not is_metal | bool
tags:
- always
roles:
- role: "os_neutron"
neutron_overlay_network: "{{ _overlay_network }}"
neutron_provider_networks: "{{ _provider_networks }}"
neutron_local_ip: "{{ _local_ip|default('127.0.0.1') }}"
neutron_local_ip: "{{ tunnel_address }}"
- role: "bird"
when:
- "'neutron_calico_dhcp_agent' in group_names"
Expand Down
35 changes: 3 additions & 32 deletions playbooks/os-nova-install.yml
Expand Up @@ -19,6 +19,9 @@
max_fail_percentage: 20
user: root
pre_tasks:
- include: common-tasks/dynamic-address-fact.yml
vars:
network_address: "management_address"
- include: common-tasks/os-lxc-container-setup.yml
vars:
extra_container_config_no_restart:
Expand Down Expand Up @@ -134,38 +137,6 @@
- kvm_device.stat.ischr is defined and kvm_device.stat.ischr
tags:
- always
- name: Set nova management bridge (is_metal)
set_fact:
management_bridge: "{{ 'ansible_' + hostvars[inventory_hostname]['management_bridge'] | replace('-', '_') }}"
when:
- "hostvars[inventory_hostname]['management_bridge'] is defined"
- "is_metal | bool"
tags:
- always
- name: Set nova management address (is_metal)
set_fact:
management_address: "{{ hostvars[inventory_hostname][management_bridge]['ipv4']['address'] }}"
when:
- "hostvars[inventory_hostname][management_bridge]['ipv4']['address'] is defined"
- "is_metal | bool"
tags:
- always
- name: Set nova management address (container)
set_fact:
management_address: "{{ hostvars[inventory_hostname]['container_networks']['container_address']['address'] }}"
when:
- "management_address is undefined"
- "hostvars[inventory_hostname]['container_networks']['container_address']['address'] is defined"
- "not is_metal | bool"
tags:
- always
- name: Set nova management address (unknown management network)
set_fact:
management_address: "{{ ansible_host }}"
when:
- "management_address is undefined"
tags:
- always
roles:
- role: "os_nova"
nova_novncproxy_git_repo: "{{ openstack_repo_git_url }}/novnc"
Expand Down

0 comments on commit 4c04c68

Please sign in to comment.