From 66ccc1a2608e4cd5a64ecd68d33601c5166ba72f Mon Sep 17 00:00:00 2001 From: Andy McCrae Date: Mon, 13 Jul 2015 14:22:18 +0100 Subject: [PATCH] Adjust the network rings are syncd on Swift nodes don't have to be able to talk to each other on the ansible_ssh_host, but will always have to talk on the storage_network specified. This will allow us to let remote or local hosts, that can't connect to each other on the ansible_ssh_host address to still be able to sync their rings. In order to achieve this we set a swift_storage_address fact which then simplifies the "ring_contents" file, to avoid performing the same logic twice. Change-Id: Ic1f2a915244101ad4fbbe52496dd2b991915d01d Partially-Implements: blueprint multi-region-swift --- .../roles/os_swift/tasks/swift_rings.yml | 2 + .../os_swift/tasks/swift_rings_distribute.yml | 4 +- .../os_swift/tasks/swift_storage_address.yml | 37 +++++++++++++++++++ .../roles/os_swift/templates/ring.contents.j2 | 8 +--- 4 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 playbooks/roles/os_swift/tasks/swift_storage_address.yml diff --git a/playbooks/roles/os_swift/tasks/swift_rings.yml b/playbooks/roles/os_swift/tasks/swift_rings.yml index 347b7a5d85..890601c7fe 100644 --- a/playbooks/roles/os_swift/tasks/swift_rings.yml +++ b/playbooks/roles/os_swift/tasks/swift_rings.yml @@ -15,6 +15,8 @@ - include: swift_rings_md5sum.yml +- include: swift_storage_address.yml + - include: swift_rings_check.yml when: > inventory_hostname == groups['swift_hosts'][0] diff --git a/playbooks/roles/os_swift/tasks/swift_rings_distribute.yml b/playbooks/roles/os_swift/tasks/swift_rings_distribute.yml index aeadc5f3d5..c39499b053 100644 --- a/playbooks/roles/os_swift/tasks/swift_rings_distribute.yml +++ b/playbooks/roles/os_swift/tasks/swift_rings_distribute.yml @@ -17,7 +17,7 @@ shell: | rsync -e 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \ -avz \ - {{ swift_system_user_name }}@{{ hostvars[groups['swift_hosts'][0]]['ansible_ssh_host'] }}:/etc/swift/ring_build_files/ \ + {{ swift_system_user_name }}@{{ hostvars[groups['swift_hosts'][0]]['swift_storage_address'] }}:/etc/swift/ring_build_files/ \ /etc/swift/ sudo: yes sudo_user: "{{ swift_system_user_name }}" @@ -30,7 +30,7 @@ shell: | rsync -e 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \ -avz \ - {{ swift_system_user_name }}@{{ hostvars[groups['swift_hosts'][0]]['ansible_ssh_host'] }}:/etc/swift/ring_build_files/ \ + {{ swift_system_user_name }}@{{ hostvars[groups['swift_hosts'][0]]['swift_storage_address'] }}:/etc/swift/ring_build_files/ \ /etc/swift/ring_build_files/ sudo: yes sudo_user: "{{ swift_system_user_name }}" diff --git a/playbooks/roles/os_swift/tasks/swift_storage_address.yml b/playbooks/roles/os_swift/tasks/swift_storage_address.yml new file mode 100644 index 0000000000..5938acc2f1 --- /dev/null +++ b/playbooks/roles/os_swift/tasks/swift_storage_address.yml @@ -0,0 +1,37 @@ +--- +# Copyright 2014, 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. + +# We need the storage network for replication of the ring +# We find the IP on the "storage_bridge" network for storage hosts +- name: Register a fact for the default storage IP swift hosts + set_fact: + swift_storage_address: "{{ hostvars[inventory_hostname]['swift_vars']['storage_ip'] | default(hostvars[inventory_hostname]['ansible_' + swift.storage_network|replace('-','_')]['ipv4']['address'] | default(hostvars[inventory_hostname]['ansible_ssh_host'])) }}" + when: inventory_hostname in groups['swift_hosts'] and + swift.storage_network is defined + +# For proxy servers this is mapped to an interface that isn't the bridge +- name: Register a fact for the default storage IP on proxy servers + set_fact: + swift_storage_address: "{{ item.value.address }}" + with_dict: container_networks + when: inventory_hostname in groups['swift_proxy'] and + swift.storage_network is defined and + item.value.bridge == swift.storage_network + +# A catchall, and for remote hosts the IP is just the ansible_ssh_host IP +- name: Register a fact for the default storage IP when no storage-network is defined or for remote hosts + set_fact: + swift_storage_address: "{{ hostvars[inventory_hostname]['ansible_ssh_host'] }}" + when: swift.storage_network is not defined diff --git a/playbooks/roles/os_swift/templates/ring.contents.j2 b/playbooks/roles/os_swift/templates/ring.contents.j2 index 835fd0f254..d12ce0b757 100644 --- a/playbooks/roles/os_swift/templates/ring.contents.j2 +++ b/playbooks/roles/os_swift/templates/ring.contents.j2 @@ -47,11 +47,7 @@ {### Loop through the swift_hosts #} {% for host in groups['swift_hosts'] %} {### Set the default storage_ip #} -{% set def_storage_ip = hostvars[host]['ansible_ssh_host'] %} -{% if swift.storage_network is defined %} -{% set storage_bridge = 'ansible_' + swift.storage_network|replace('-', '_') %} -{% set def_storage_ip = hostvars[host][storage_bridge]['ipv4']['address'] | default(hostvars[host]['ansible_ssh_host']) %} -{% endif %} +{% set def_storage_ip = hostvars[host]['swift_storage_address'] %} {### Set the default replication_ip #} {% set def_repl_ip = def_storage_ip %} {% if swift.replication_network is defined %} @@ -80,7 +76,7 @@ {% set zone = drive.zone | default(swift_vars.zone | default(swift.zone | default(swift_default_host_zone))) %} {% set repl_ip = drive.repl_ip | default(swift_vars.repl_ip | default(def_repl_ip)) %} {% set repl_port = drive.repl_port | default(swift_vars.repl_port | default(port)) %} -{% set storage_ip = drive.storage_ip | default(swift_vars.storage_ip | default(def_storage_ip)) %} +{% set storage_ip = drive.storage_ip | default(def_storage_ip) %} {% set storage_port = drive.storage_port | default(swift_vars.storage_port | default(port)) %} {### Update the device with the appropriate values #} {% set _update = device.update({'device':drive.name}) %}