From de8b857668f8f172887b947d31e76f970d58144e Mon Sep 17 00:00:00 2001 From: Andy McCrae Date: Mon, 20 Jul 2015 16:07:23 +0100 Subject: [PATCH] Add swift-sync role and environment Add the swift-remote host group and environment file. Add an os_swift_sync role which will sync the swift ring and ssh keys for swift hosts (remote and not-remote). Which has the following: * Moves the key and ring tasks out of os_swift role to os_swift_sync. * This adds the use of the "-r" flag that was added to the swift_rings.py and swift_rings_check.py. * Adds a ring.builder vs contents file consistency check. * Adjusts the rsync process to use the built-in synchronize module * Ensure services have started post ring/ssh key sync. Adds environment file and sample configuration file for swift-remote hosts (conf.d). Move appropriate default vars to the os_swift_sync role, and remove them from the os_swift role. Rename the "os-swift-install.yml" playbook to "os-swift-setup.yml" as this handles only the setup, and add a playbook to for both os-swift-sync.yml and an overarching playbook (os-swift-install.yml) that will call both the os-swift-sync.yml and os-swift-setup.yml playbooks. This means the funcitonality of "os-swift-install.yml" remains unchanged. Adjust the run-playbooks.sh so that it calls the new overarching swift playbook. Change-Id: Ie2d8041b4bc46f092a96882fe3ca430be92195ed Partially-Implements: blueprint multi-region-swift --- .../conf.d/swift-remote.yml.sample | 22 ++ etc/openstack_deploy/env.d/swift-remote.yml | 40 ++++ playbooks/os-swift-install.yml | 49 +---- playbooks/os-swift-setup.yml | 64 ++++++ playbooks/os-swift-sync.yml | 27 +++ playbooks/roles/os_swift/defaults/main.yml | 5 - playbooks/roles/os_swift/tasks/main.yml | 9 - .../os_swift/tasks/swift_pre_install.yml | 2 +- .../os_swift/tasks/swift_storage_address.yml | 37 ---- .../roles/os_swift_sync/CONTRIBUTING.rst | 85 ++++++++ playbooks/roles/os_swift_sync/LICENSE | 202 ++++++++++++++++++ playbooks/roles/os_swift_sync/README.rst | 18 ++ .../roles/os_swift_sync/defaults/main.yml | 59 +++++ .../files/swift_rings.py | 0 .../os_swift_sync/files/swift_rings_check.py | 174 +++++++++++++++ playbooks/roles/os_swift_sync/meta/main.yml | 31 +++ playbooks/roles/os_swift_sync/tasks/main.yml | 27 +++ .../tasks/swift_key_distribute.yml | 2 +- .../tasks/swift_key_populate.yml | 0 .../tasks/swift_key_setup.yml | 0 .../tasks/swift_rings.yml | 4 +- .../tasks/swift_rings_build.yml | 30 +++ .../tasks/swift_rings_check.yml | 7 +- .../tasks/swift_rings_distribute.yml | 26 +-- .../tasks/swift_rings_md5sum.yml | 0 .../swift_rings_post_distribution_check.yml | 99 +++++++++ .../tasks/swift_sync_post_install.yml | 30 +++ .../templates/ring.contents.j2 | 8 +- 28 files changed, 936 insertions(+), 121 deletions(-) create mode 100644 etc/openstack_deploy/conf.d/swift-remote.yml.sample create mode 100644 etc/openstack_deploy/env.d/swift-remote.yml create mode 100644 playbooks/os-swift-setup.yml create mode 100644 playbooks/os-swift-sync.yml delete mode 100644 playbooks/roles/os_swift/tasks/swift_storage_address.yml create mode 100644 playbooks/roles/os_swift_sync/CONTRIBUTING.rst create mode 100644 playbooks/roles/os_swift_sync/LICENSE create mode 100644 playbooks/roles/os_swift_sync/README.rst create mode 100644 playbooks/roles/os_swift_sync/defaults/main.yml rename playbooks/roles/{os_swift => os_swift_sync}/files/swift_rings.py (100%) create mode 100644 playbooks/roles/os_swift_sync/files/swift_rings_check.py create mode 100644 playbooks/roles/os_swift_sync/meta/main.yml create mode 100644 playbooks/roles/os_swift_sync/tasks/main.yml rename playbooks/roles/{os_swift => os_swift_sync}/tasks/swift_key_distribute.yml (92%) rename playbooks/roles/{os_swift => os_swift_sync}/tasks/swift_key_populate.yml (100%) rename playbooks/roles/{os_swift => os_swift_sync}/tasks/swift_key_setup.yml (100%) rename playbooks/roles/{os_swift => os_swift_sync}/tasks/swift_rings.yml (93%) rename playbooks/roles/{os_swift => os_swift_sync}/tasks/swift_rings_build.yml (70%) rename playbooks/roles/{os_swift => os_swift_sync}/tasks/swift_rings_check.yml (82%) rename playbooks/roles/{os_swift => os_swift_sync}/tasks/swift_rings_distribute.yml (51%) rename playbooks/roles/{os_swift => os_swift_sync}/tasks/swift_rings_md5sum.yml (100%) create mode 100644 playbooks/roles/os_swift_sync/tasks/swift_rings_post_distribution_check.yml create mode 100644 playbooks/roles/os_swift_sync/tasks/swift_sync_post_install.yml rename playbooks/roles/{os_swift => os_swift_sync}/templates/ring.contents.j2 (91%) diff --git a/etc/openstack_deploy/conf.d/swift-remote.yml.sample b/etc/openstack_deploy/conf.d/swift-remote.yml.sample new file mode 100644 index 0000000000..81a336178f --- /dev/null +++ b/etc/openstack_deploy/conf.d/swift-remote.yml.sample @@ -0,0 +1,22 @@ +--- +# For remote swift hosts you will only specify the IP address +# NB. The ip address that must be specified is the IP address that swift +# hosts will be able to replicate on and not necessarily the +# ansible_ssh_host IP from the remote ansible install. +swift-remote_hosts: + remote-swift1: + ip: 172.29.237.1 + remote-swift2: + ip: 172.29.237.2 + remote-swift3: + ip: 172.29.237.3 + remote-swift4: + ip: 172.29.237.4 + remote-swift5: + ip: 172.29.237.5 + remote-swiftproxy1: + ip: 172.29.237.6 + remote-swiftproxy2: + ip: 172.29.237.7 + remote-swiftproxy3: + ip: 172.29.237.8 diff --git a/etc/openstack_deploy/env.d/swift-remote.yml b/etc/openstack_deploy/env.d/swift-remote.yml new file mode 100644 index 0000000000..1fa630c4f7 --- /dev/null +++ b/etc/openstack_deploy/env.d/swift-remote.yml @@ -0,0 +1,40 @@ +--- +# 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. + +component_skel: + swift_remote: + belongs_to: + - swift_remote_all + + +container_skel: + swift_remote_container: + belongs_to: + - swift-remote_containers + contains: + - swift_remote + properties: + is_metal: true + service_name: swift + container_release: trusty + + +physical_skel: + swift-remote_containers: + belongs_to: + - remote_containers + swift-remote_hosts: + belongs_to: + - remote diff --git a/playbooks/os-swift-install.yml b/playbooks/os-swift-install.yml index c555a57c4b..a6517ad9ad 100644 --- a/playbooks/os-swift-install.yml +++ b/playbooks/os-swift-install.yml @@ -13,50 +13,5 @@ # See the License for the specific language governing permissions and # limitations under the License. -- name: Installation and setup of Swift - hosts: swift_all - max_fail_percentage: 20 - user: root - pre_tasks: - - name: Create log dir - file: - path: "{{ item.path }}" - state: directory - with_items: - - { path: "/openstack/log/{{ inventory_hostname }}-swift" } - when: is_metal == true or is_metal == "True" - tags: - - swift-logs - - swift-log-dirs - - name: Create log aggregation links - file: - src: "{{ item.src }}" - dest: "{{ item.dest }}" - state: "{{ item.state }}" - owner: "{{ item.owner }}" - group: "{{ item.group }}" - force: "yes" - with_items: - - src: "/openstack/log/{{ inventory_hostname }}-swift" - dest: "/var/log/swift" - owner: "syslog" - group: "syslog" - state: "link" - when: is_metal == true or is_metal == "True" - tags: - - swift-logs - roles: - - { role: "os_swift", tags: [ "os-swift" ] } - - role: "rsyslog_client" - rsyslog_client_log_dir: "/var/log/swift" - rsyslog_client_config_name: "99-swift-rsyslog-client.conf" - tags: - - "swift-rsyslog-client" - - "rsyslog-client" - - role: "system_crontab_coordination" - tags: - - "system-crontab-coordination" - vars: - ansible_hostname: "{{ container_name }}" - ansible_ssh_host: "{{ container_address }}" - is_metal: "{{ properties.is_metal|default(false) }}" +- include: os-swift-setup.yml +- include: os-swift-sync.yml diff --git a/playbooks/os-swift-setup.yml b/playbooks/os-swift-setup.yml new file mode 100644 index 0000000000..8546f6c0c9 --- /dev/null +++ b/playbooks/os-swift-setup.yml @@ -0,0 +1,64 @@ +--- +# 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. + +# This playbook will install the swift services but not sync the ring or keys. + +- name: Installation and setup of Swift + hosts: swift_all + max_fail_percentage: 20 + user: root + pre_tasks: + - name: Create log dir + file: + path: "{{ item.path }}" + state: directory + with_items: + - { path: "/openstack/log/{{ inventory_hostname }}-swift" } + when: is_metal == true or is_metal == "True" + tags: + - swift-logs + - swift-log-dirs + - name: Create log aggregation links + file: + src: "{{ item.src }}" + dest: "{{ item.dest }}" + state: "{{ item.state }}" + owner: "{{ item.owner }}" + group: "{{ item.group }}" + force: "yes" + with_items: + - src: "/openstack/log/{{ inventory_hostname }}-swift" + dest: "/var/log/swift" + owner: "syslog" + group: "syslog" + state: "link" + when: is_metal == true or is_metal == "True" + tags: + - swift-logs + roles: + - { role: "os_swift", tags: [ "os-swift" ] } + - role: "rsyslog_client" + rsyslog_client_log_dir: "/var/log/swift" + rsyslog_client_config_name: "99-swift-rsyslog-client.conf" + tags: + - "swift-rsyslog-client" + - "rsyslog-client" + - role: "system_crontab_coordination" + tags: + - "system-crontab-coordination" + vars: + ansible_hostname: "{{ container_name }}" + ansible_ssh_host: "{{ container_address }}" + is_metal: "{{ properties.is_metal|default(false) }}" diff --git a/playbooks/os-swift-sync.yml b/playbooks/os-swift-sync.yml new file mode 100644 index 0000000000..7f1d020d81 --- /dev/null +++ b/playbooks/os-swift-sync.yml @@ -0,0 +1,27 @@ +--- +# 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. + +# Playbook will sync the swift ring and ssh keys +# The services need to be installed first though. +- name: Synchronisation of swift ring and ssh keys + hosts: swift_all:swift_remote_all + max_fail_percentage: 20 + user: root + roles: + - { role: "os_swift_sync", tags: [ "os-swift-sync" ] } + vars: + ansible_hostname: "{{ container_name }}" + ansible_ssh_host: "{{ container_address }}" + is_metal: "{{ properties.is_metal|default(false) }}" diff --git a/playbooks/roles/os_swift/defaults/main.yml b/playbooks/roles/os_swift/defaults/main.yml index 79333ff4dd..3b937fbb04 100644 --- a/playbooks/roles/os_swift/defaults/main.yml +++ b/playbooks/roles/os_swift/defaults/main.yml @@ -67,11 +67,6 @@ swift_keystone_auth_plugin: "password" ## Swift default variables swift_dispersion_user: dispersion swift_operator_role: swiftoperator -swift_default_replication_number: 3 -swift_default_min_part_hours: 1 -swift_default_host_zone: 0 -swift_default_host_region: 1 -swift_default_drive_weight: 100 swift_allow_versions: True # This will allow all users to create containers and upload to swift if set to True swift_allow_all_users: False diff --git a/playbooks/roles/os_swift/tasks/main.yml b/playbooks/roles/os_swift/tasks/main.yml index e58722a86e..243d2c300b 100644 --- a/playbooks/roles/os_swift/tasks/main.yml +++ b/playbooks/roles/os_swift/tasks/main.yml @@ -17,15 +17,6 @@ - include: swift_install.yml - include: swift_post_install.yml -- include: swift_key_setup.yml - tags: - - swift-key - - swift-key-distribute - -- include: swift_rings.yml - tags: - - swift-rings - - include: swift_storage_hosts.yml when: > inventory_hostname in groups['swift_hosts'] diff --git a/playbooks/roles/os_swift/tasks/swift_pre_install.yml b/playbooks/roles/os_swift/tasks/swift_pre_install.yml index f9e7c01a94..3a23fc321f 100644 --- a/playbooks/roles/os_swift/tasks/swift_pre_install.yml +++ b/playbooks/roles/os_swift/tasks/swift_pre_install.yml @@ -29,7 +29,7 @@ - "{{ swift_system_home_folder }}/.ssh/authorized_keys" - "{{ swift_system_home_folder }}/.ssh/id_rsa" - "{{ swift_system_home_folder }}/.ssh/id_rsa.pub" - when: swift_recreate_keys == True + when: swift_recreate_keys | bool tags: - swift-key - swift-key-create diff --git a/playbooks/roles/os_swift/tasks/swift_storage_address.yml b/playbooks/roles/os_swift/tasks/swift_storage_address.yml deleted file mode 100644 index 5938acc2f1..0000000000 --- a/playbooks/roles/os_swift/tasks/swift_storage_address.yml +++ /dev/null @@ -1,37 +0,0 @@ ---- -# 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_sync/CONTRIBUTING.rst b/playbooks/roles/os_swift_sync/CONTRIBUTING.rst new file mode 100644 index 0000000000..50f4ec2dad --- /dev/null +++ b/playbooks/roles/os_swift_sync/CONTRIBUTING.rst @@ -0,0 +1,85 @@ +OpenStack swift key & ring sync +############################### +:tags: openstack, swift, cloud, ansible +:category: \*nix + +contributor guidelines +^^^^^^^^^^^^^^^^^^^^^^ + +Filing Bugs +----------- + +Bugs should be filed on Launchpad, not GitHub: "https://bugs.launchpad.net/openstack-ansible" + + +When submitting a bug, or working on a bug, please ensure the following criteria are met: + * The description clearly states or describes the original problem or root cause of the problem. + * Include historical information on how the problem was identified. + * Any relevant logs are included. + * The provided information should be totally self-contained. External access to web services/sites should not be needed. + * Steps to reproduce the problem if possible. + + +Submitting Code +--------------- + +Changes to the project should be submitted for review via the Gerrit tool, following +the workflow documented at: "http://docs.openstack.org/infra/manual/developers.html#development-workflow" + +Pull requests submitted through GitHub will be ignored and closed without regard. + + +Extra +----- + +Tags: + If it's a bug that needs fixing in a branch in addition to Master, add a '\-backport-potential' tag (eg ``juno-backport-potential``). There are predefined tags that will autocomplete. + +Status: + Please leave this alone, it should be New till someone triages the issue. + +Importance: + Should only be touched if it is a Blocker/Gating issue. If it is, please set to High, and only use Critical if you have found a bug that can take down whole infrastructures. + + +Style guide +----------- + +When creating tasks and other roles for use in Ansible please create then using the YAML dictionary format. + +Example YAML dictionary format: + .. code-block:: yaml + + - name: The name of the tasks + module_name: + thing1: "some-stuff" + thing2: "some-other-stuff" + tags: + - some-tag + - some-other-tag + + +Example **NOT** in YAML dictionary format: + .. code-block:: yaml + + - name: The name of the tasks + module_name: thing1="some-stuff" thing2="some-other-stuff" + tags: + - some-tag + - some-other-tag + + +Usage of the ">" and "|" operators should be limited to Ansible conditionals and command modules such as the ansible ``shell`` module. + + +Issues +------ + +When submitting an issue, or working on an issue please ensure the following criteria are met: + * The description clearly states or describes the original problem or root cause of the problem. + * Include historical information on how the problem was identified. + * Any relevant logs are included. + * If the issue is a bug that needs fixing in a branch other than Master, add the ‘backport potential’ tag TO THE ISSUE (not the PR). + * The provided information should be totally self-contained. External access to web services/sites should not be needed. + * If the issue is needed for a hotfix release, add the 'expedite' label. + * Steps to reproduce the problem if possible. diff --git a/playbooks/roles/os_swift_sync/LICENSE b/playbooks/roles/os_swift_sync/LICENSE new file mode 100644 index 0000000000..e06d208186 --- /dev/null +++ b/playbooks/roles/os_swift_sync/LICENSE @@ -0,0 +1,202 @@ +Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + 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. + diff --git a/playbooks/roles/os_swift_sync/README.rst b/playbooks/roles/os_swift_sync/README.rst new file mode 100644 index 0000000000..76fe50516b --- /dev/null +++ b/playbooks/roles/os_swift_sync/README.rst @@ -0,0 +1,18 @@ +OpenStack swift key/ring sync +############################# +:tags: openstack, swift, cloud, ansible +:category: \*nix + +Role to synchronise keys and the ring for swift hosts + +This role will synchronise the following: + * ring + * ssh keys + +.. code-block:: yaml + + - name: Sync swift rings and keys + hosts: swift_all:swift_remote_all + user: root + roles: + - { role: "os_swift_sync", tags: [ "os-swift-sync" ] } diff --git a/playbooks/roles/os_swift_sync/defaults/main.yml b/playbooks/roles/os_swift_sync/defaults/main.yml new file mode 100644 index 0000000000..04695f3aa0 --- /dev/null +++ b/playbooks/roles/os_swift_sync/defaults/main.yml @@ -0,0 +1,59 @@ +--- +# 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. + +# Set the managed regions as a list of swift regions to manage +# Use for global clusters, default when not set is all regions. +# swift_managed_regions: +# - 1 +# - 2 + +swift_proxy_port: "8080" +swift_object_port: "6000" +swift_container_port: "6001" +swift_account_port: "6002" + +swift_default_replication_number: 3 +swift_default_min_part_hours: 1 +swift_default_host_zone: 0 +swift_default_host_region: 1 +swift_default_drive_weight: 100 + +swift_account_program_names: + - swift-account-server + - swift-account-auditor + - swift-account-replicator + - swift-account-reaper + - swift-account-replicator-server + +swift_container_program_names: + - swift-container-server + - swift-container-auditor + - swift-container-replicator + - swift-container-sync + - swift-container-updater + - swift-container-replicator-server + +swift_object_program_names: + - swift-object-server + - swift-object-auditor + - swift-object-replicator + - swift-object-updater + - swift-object-replicator-server + +swift_proxy_program_names: + - swift-proxy-server + +swift_system_user_name: swift +swift_system_home_folder: "/var/lib/{{ swift_system_user_name }}" diff --git a/playbooks/roles/os_swift/files/swift_rings.py b/playbooks/roles/os_swift_sync/files/swift_rings.py similarity index 100% rename from playbooks/roles/os_swift/files/swift_rings.py rename to playbooks/roles/os_swift_sync/files/swift_rings.py diff --git a/playbooks/roles/os_swift_sync/files/swift_rings_check.py b/playbooks/roles/os_swift_sync/files/swift_rings_check.py new file mode 100644 index 0000000000..24cb2962c6 --- /dev/null +++ b/playbooks/roles/os_swift_sync/files/swift_rings_check.py @@ -0,0 +1,174 @@ +#!/usr/bin/env python +# 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. + +from __future__ import print_function +from optparse import OptionParser +from os.path import exists + +import json +import pickle +import sys + +USAGE = "usage: %prog -f -r " + +DEVICE_KEY = "%(ip)s:%(port)d/%(device)s" + + +class RingComparisonError(Exception): + pass + + +def get_build_file_data(build_file): + build_file_data = None + if exists(build_file): + try: + with open(build_file) as bf_stream: + build_file_data = pickle.load(bf_stream) + except Exception as ex: + print("Error: failed to load build file '%s': %s" % (build_file, + ex)) + build_file_data = None + return build_file_data + + +def check_ring_settings(build_file, part_power, repl, min_part_hours, + data=None): + # Check if the build file is emptuy + if data is None: + raise RingComparisonError('Build file %s is empty or does ' + 'not exist.' % build_file) + # Check if replica count matches for contents and ring file + if repl != data.get('replicas'): + raise RingComparisonError('Replica count does not match') + # Check min_part_hours matches for contents and ring file + if min_part_hours != data.get('min_part_hours'): + raise RingComparisonError('min_part_hours does not match') + # Check part_power matches for contents and ring file + if part_power != data.get('part_power'): + raise RingComparisonError('part_power does not match') + + +def check_host_settings(content_host, ring_host): + devstr = DEVICE_KEY % content_host + if content_host.get('zone', 0) != ring_host['zone']: + raise RingComparisonError('Zone on device %s differs to the ring.' + % devstr) + if content_host.get('region', 1) != ring_host['region']: + raise RingComparisonError('Region on device %s differs to the ring.' + % devstr) + + content_repl_ip = content_host.get('repl_ip', content_host['ip']) + content_repl_port = content_host.get('repl_port', content_host['port']) + content_weight = content_host.get('weight') + ring_repl_ip = ring_host['replication_ip'] + ring_repl_port = ring_host['replication_port'] + ring_weight = ring_host['weight'] + if content_repl_ip != ring_repl_ip: + raise RingComparisonError('Replication IP for device %s differs ' + 'to the ring.' % devstr) + if content_repl_port != ring_repl_port: + raise RingComparisonError('Replication Port for device %s differs ' + 'to the ring.' % devstr) + if content_weight != ring_weight: + raise RingComparisonError('Device weight for device %s differs to the ' + 'ring.' % devstr) + + +def check_ring(build_name, repl, min_part_hours, part_power, content_hosts, + region=None): + build_file = "%s.builder" % build_name + build_file_data = get_build_file_data(build_file) + check_ring_settings( + build_file, + part_power, + repl, + min_part_hours, + data=build_file_data + ) + + ring_hosts = {} + for i, dev in enumerate(build_file_data['devs']): + if dev is not None: + if region is None or int(region) == int(dev['region']): + ring_hosts[DEVICE_KEY % dev] = i + for content_host in content_hosts: + host_key = DEVICE_KEY % content_host + if region is None or int(region) == int(content_host['region']): + if host_key in ring_hosts: + ring_host = build_file_data['devs'][ring_hosts[host_key]] + check_host_settings(content_host, ring_host) + ring_hosts.pop(host_key) + else: + raise RingComparisonError('Device %s is not in the ring.' + % host_key) + + if ring_hosts: + for ring_host in ring_hosts: + if build_file_data['devs'][ring_hosts[ring_host]]['weight'] != 0: + raise RingComparisonError('There are devices in the ring that' + 'are not in the inventory/contents' + 'file.') + + +def main(setup, region): + # load the json file + try: + with open(setup) as json_stream: + _contents_file = json.load(json_stream) + except Exception as ex: + print("Failed to load json string %s" % ex) + return 1 + + content_hosts = _contents_file['drives'] + kargs = {'content_hosts': content_hosts, 'region': region} + ring_call = [ + _contents_file['builder_file'], + _contents_file['repl_number'], + _contents_file['min_part_hours'], + _contents_file['part_power'] + ] + + try: + check_ring(*ring_call, **kargs) + print('SUCCESS: Ring is consistent with contents file') + except RingComparisonError as ex: + print(ex) + return 2 + +if __name__ == "__main__": + parser = OptionParser(USAGE) + parser.add_option( + "-f", + "--file", + dest="setup", + help="Specify the swift ring contents file.", + metavar="FILE" + ) + parser.add_option( + "-r", + "--region", + help="Specify the region to manage for the ring file.", + dest="region", + type='int', + metavar="REGION" + ) + + options, _args = parser.parse_args(sys.argv[1:]) + if options.setup and not exists(options.setup): + print("Swift ring contents file not found or doesn't exist") + parser.print_help() + sys.exit(1) + + sys.exit(main(options.setup, options.region)) diff --git a/playbooks/roles/os_swift_sync/meta/main.yml b/playbooks/roles/os_swift_sync/meta/main.yml new file mode 100644 index 0000000000..635efd71ee --- /dev/null +++ b/playbooks/roles/os_swift_sync/meta/main.yml @@ -0,0 +1,31 @@ +--- +# 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. + +galaxy_info: + author: rcbops + description: Synchronisation of swift ring and ssh keys + company: Rackspace + license: Apache2 + min_ansible_version: 1.6.6 + platforms: + - name: Ubuntu + versions: + - trusty + categories: + - cloud + - python + - swift + - development + - openstack diff --git a/playbooks/roles/os_swift_sync/tasks/main.yml b/playbooks/roles/os_swift_sync/tasks/main.yml new file mode 100644 index 0000000000..84fe204655 --- /dev/null +++ b/playbooks/roles/os_swift_sync/tasks/main.yml @@ -0,0 +1,27 @@ +--- +# 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. + +- include: swift_key_setup.yml + tags: + - swift-key + - swift-key-distribute + +- include: swift_rings.yml + tags: + - swift-rings + +- include: swift_sync_post_install.yml + tags: + - swift-sync-post-install diff --git a/playbooks/roles/os_swift/tasks/swift_key_distribute.yml b/playbooks/roles/os_swift_sync/tasks/swift_key_distribute.yml similarity index 92% rename from playbooks/roles/os_swift/tasks/swift_key_distribute.yml rename to playbooks/roles/os_swift_sync/tasks/swift_key_distribute.yml index f812921d3f..70bdddc97a 100644 --- a/playbooks/roles/os_swift/tasks/swift_key_distribute.yml +++ b/playbooks/roles/os_swift_sync/tasks/swift_key_distribute.yml @@ -17,7 +17,7 @@ authorized_key: user: "{{ swift_system_user_name }}" key: "{{ hostvars[item]['swift_pubkey'] }}" - with_items: groups['swift_all'] + with_items: groups['swift_all'] + groups['swift_remote_all'] tags: - swift-key - swift-key-create diff --git a/playbooks/roles/os_swift/tasks/swift_key_populate.yml b/playbooks/roles/os_swift_sync/tasks/swift_key_populate.yml similarity index 100% rename from playbooks/roles/os_swift/tasks/swift_key_populate.yml rename to playbooks/roles/os_swift_sync/tasks/swift_key_populate.yml diff --git a/playbooks/roles/os_swift/tasks/swift_key_setup.yml b/playbooks/roles/os_swift_sync/tasks/swift_key_setup.yml similarity index 100% rename from playbooks/roles/os_swift/tasks/swift_key_setup.yml rename to playbooks/roles/os_swift_sync/tasks/swift_key_setup.yml diff --git a/playbooks/roles/os_swift/tasks/swift_rings.yml b/playbooks/roles/os_swift_sync/tasks/swift_rings.yml similarity index 93% rename from playbooks/roles/os_swift/tasks/swift_rings.yml rename to playbooks/roles/os_swift_sync/tasks/swift_rings.yml index 125a775363..3d25b02b47 100644 --- a/playbooks/roles/os_swift/tasks/swift_rings.yml +++ b/playbooks/roles/os_swift_sync/tasks/swift_rings.yml @@ -15,8 +15,6 @@ - include: swift_rings_md5sum.yml -- include: swift_storage_address.yml - - include: swift_rings_check.yml when: > inventory_hostname == groups['swift_hosts'][0] @@ -29,6 +27,6 @@ - include: swift_rings_md5sum.yml -- include: swift_rings_check.yml +- include: swift_rings_post_distribution_check.yml when: > inventory_hostname == groups['swift_hosts'][0] diff --git a/playbooks/roles/os_swift/tasks/swift_rings_build.yml b/playbooks/roles/os_swift_sync/tasks/swift_rings_build.yml similarity index 70% rename from playbooks/roles/os_swift/tasks/swift_rings_build.yml rename to playbooks/roles/os_swift_sync/tasks/swift_rings_build.yml index 0bade2f0aa..1cc5320f61 100644 --- a/playbooks/roles/os_swift/tasks/swift_rings_build.yml +++ b/playbooks/roles/os_swift_sync/tasks/swift_rings_build.yml @@ -55,6 +55,21 @@ with_items: - account - container + when: swift_managed_regions is not defined + sudo: yes + sudo_user: "{{ swift_system_user_name }}" + args: + chdir: /etc/swift/ring_build_files/ + tags: + - swift-rings + - swift-rings-build + +- name: "build rings for account/container from contents files" + command: "/usr/bin/python /etc/swift/scripts/swift_rings.py -f /etc/swift/scripts/{{ item[0] }}.contents -r {{ item[1] }}" + with_nested: + - [ 'account', 'container' ] + - "{{ swift_managed_regions }}" + when: swift_managed_regions is defined sudo: yes sudo_user: "{{ swift_system_user_name }}" args: @@ -67,6 +82,21 @@ command: "/usr/bin/python /etc/swift/scripts/swift_rings.py -f /etc/swift/scripts/object-{{ item.policy.index }}.contents" with_items: - "{{ swift.storage_policies }}" + when: swift_managed_regions is not defined + sudo: yes + sudo_user: "{{ swift_system_user_name }}" + args: + chdir: /etc/swift/ring_build_files/ + tags: + - swift-rings + - swift-rings-build + +- name: "build rings for storage policies from contents files" + command: "/usr/bin/python /etc/swift/scripts/swift_rings.py -f /etc/swift/scripts/object-{{ item[0].policy.index }}.contents -r {{ item[1] }}" + with_nested: + - "{{ swift.storage_policies }}" + - "{{ swift_managed_regions }}" + when: swift_managed_regions is defined sudo: yes sudo_user: "{{ swift_system_user_name }}" args: diff --git a/playbooks/roles/os_swift/tasks/swift_rings_check.yml b/playbooks/roles/os_swift_sync/tasks/swift_rings_check.yml similarity index 82% rename from playbooks/roles/os_swift/tasks/swift_rings_check.yml rename to playbooks/roles/os_swift_sync/tasks/swift_rings_check.yml index aacfc6de31..c2d8270a8e 100644 --- a/playbooks/roles/os_swift/tasks/swift_rings_check.yml +++ b/playbooks/roles/os_swift_sync/tasks/swift_rings_check.yml @@ -32,11 +32,12 @@ - name: Verify md5sum of builder files fail: msg: > - "The builder files on the remote host {{ item }} do not match the {{ md5sum.stdout }}, - and are not empty on the remote host" + "The builder files on the remote host {{ item }}:{{ hostvars[item]['builder_md5sum'] }} + do not match {{ inventory_hostname }}:{{ md5sum.stdout }} + and are not empty on the remote host" when: > ("{{ hostvars[item]['builder_md5sum'] }}" != "{{ empty_md5sum.stdout }}") and ("{{ hostvars[item]['builder_md5sum'] }}" != "{{ md5sum.stdout }}") - with_items: groups['swift_all'] + with_items: groups['swift_all'] + groups['swift_remote_all'] tags: - swift-ring-check diff --git a/playbooks/roles/os_swift/tasks/swift_rings_distribute.yml b/playbooks/roles/os_swift_sync/tasks/swift_rings_distribute.yml similarity index 51% rename from playbooks/roles/os_swift/tasks/swift_rings_distribute.yml rename to playbooks/roles/os_swift_sync/tasks/swift_rings_distribute.yml index c39499b053..6645c17d31 100644 --- a/playbooks/roles/os_swift/tasks/swift_rings_distribute.yml +++ b/playbooks/roles/os_swift_sync/tasks/swift_rings_distribute.yml @@ -14,24 +14,24 @@ # limitations under the License. - name: "Get swift rings" - shell: | - rsync -e 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \ - -avz \ - {{ swift_system_user_name }}@{{ hostvars[groups['swift_hosts'][0]]['swift_storage_address'] }}:/etc/swift/ring_build_files/ \ - /etc/swift/ + synchronize: + src: "/etc/swift/ring_build_files/" + mode: push + dest: "/etc/swift/" + set_remote_user: False + delegate_to: "{{ groups['swift_hosts'][0] }}" sudo: yes sudo_user: "{{ swift_system_user_name }}" tags: - swift-get-rings -# This task will backup the swift rings files on each node -# This task will prevent an issue if swift_hosts[0] were removed/changes -- name: "Copy swift rings to /etc/swift/ring_build_files for backup" - shell: | - rsync -e 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \ - -avz \ - {{ swift_system_user_name }}@{{ hostvars[groups['swift_hosts'][0]]['swift_storage_address'] }}:/etc/swift/ring_build_files/ \ - /etc/swift/ring_build_files/ +- name: "Get swift rings for backup in ring_build_files directory" + synchronize: + src: "/etc/swift/ring_build_files/" + mode: push + dest: "/etc/swift/ring_build_files/" + set_remote_user: False + delegate_to: "{{ groups['swift_hosts'][0] }}" sudo: yes sudo_user: "{{ swift_system_user_name }}" tags: diff --git a/playbooks/roles/os_swift/tasks/swift_rings_md5sum.yml b/playbooks/roles/os_swift_sync/tasks/swift_rings_md5sum.yml similarity index 100% rename from playbooks/roles/os_swift/tasks/swift_rings_md5sum.yml rename to playbooks/roles/os_swift_sync/tasks/swift_rings_md5sum.yml diff --git a/playbooks/roles/os_swift_sync/tasks/swift_rings_post_distribution_check.yml b/playbooks/roles/os_swift_sync/tasks/swift_rings_post_distribution_check.yml new file mode 100644 index 0000000000..a8a36ee40b --- /dev/null +++ b/playbooks/roles/os_swift_sync/tasks/swift_rings_post_distribution_check.yml @@ -0,0 +1,99 @@ +--- +# 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. + +- name: Get md5sum of local builder files + shell: | + cat /etc/swift/ring_build_files/*.builder 2>/dev/null | md5sum | cut -d " " -f1 + register: md5sum + tags: + - swift-ring-check + +# Fail if the remote hosts builder files don't match +# As this is post sync all should match and not be empty +- name: Verify md5sum of builder files + fail: + msg: > + "The builder files on the remote host {{ item }}:{{ hostvars[item]['builder_md5sum'] }} + do not match {{ inventory_hostname }}:{{ md5sum.stdout }}" + when: hostvars[item]['builder_md5sum'] != md5sum.stdout + with_items: groups['swift_all'] + groups['swift_remote_all'] + tags: + - swift-ring-check + +- name: "Copy the swift_rings_check.py file" + copy: + src: swift_rings_check.py + dest: "/etc/swift/scripts/swift_rings_check.py" + owner: "{{ swift_system_user_name }}" + group: "{{ swift_system_group_name }}" + mode: "0700" + tags: + - swift-rings + - swift-rings-scripts + +- name: "Ensure contents file matches ring after ring sync for account/container" + command: "/usr/bin/python /etc/swift/scripts/swift_rings_check.py -f /etc/swift/scripts/{{ item }}.contents" + with_items: + - account + - container + when: swift_managed_regions is not defined + sudo: yes + sudo_user: "{{ swift_system_user_name }}" + args: + chdir: /etc/swift/ring_build_files/ + tags: + - swift-rings + - swift-rings-check + +- name: "Ensure contents file matches ring after ring sync for account/container" + command: "/usr/bin/python /etc/swift/scripts/swift_rings_check.py -f /etc/swift/scripts/{{ item[0] }}.contents -r {{ item[1] }}" + with_nested: + - [ 'account', 'container' ] + - "{{ swift_managed_regions }}" + when: swift_managed_regions is defined + sudo: yes + sudo_user: "{{ swift_system_user_name }}" + args: + chdir: /etc/swift/ring_build_files/ + tags: + - swift-rings + - swift-rings-check + +- name: "Ensure contents file matches ring after ring sync for storage policies" + command: "/usr/bin/python /etc/swift/scripts/swift_rings_check.py -f /etc/swift/scripts/object-{{ item.policy.index }}.contents" + with_items: + - "{{ swift.storage_policies }}" + when: swift_managed_regions is not defined + sudo: yes + sudo_user: "{{ swift_system_user_name }}" + args: + chdir: /etc/swift/ring_build_files/ + tags: + - swift-rings + - swift-rings-check + +- name: "Ensure contents file matches ring after ring sync for storage policies" + command: "/usr/bin/python /etc/swift/scripts/swift_rings_check.py -f /etc/swift/scripts/object-{{ item[0].policy.index }}.contents -r {{ item[1] }}" + with_nested: + - "{{ swift.storage_policies }}" + - "{{ swift_managed_regions }}" + when: swift_managed_regions is defined + sudo: yes + sudo_user: "{{ swift_system_user_name }}" + args: + chdir: /etc/swift/ring_build_files/ + tags: + - swift-rings + - swift-rings-check diff --git a/playbooks/roles/os_swift_sync/tasks/swift_sync_post_install.yml b/playbooks/roles/os_swift_sync/tasks/swift_sync_post_install.yml new file mode 100644 index 0000000000..b55373743a --- /dev/null +++ b/playbooks/roles/os_swift_sync/tasks/swift_sync_post_install.yml @@ -0,0 +1,30 @@ +--- +# 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. + +- name: "Ensure services are started" + service: + name: "{{ item }}" + state: "started" + pattern: "{{ item }}" + with_items: swift_account_program_names + swift_container_program_names + swift_object_program_names + when: inventory_hostname in groups['swift_hosts'] + +- name: "Ensure services are started" + service: + name: "{{ item }}" + state: "started" + pattern: "{{ item }}" + with_items: swift_proxy_program_names + when: inventory_hostname in groups['swift_proxy'] diff --git a/playbooks/roles/os_swift/templates/ring.contents.j2 b/playbooks/roles/os_swift_sync/templates/ring.contents.j2 similarity index 91% rename from playbooks/roles/os_swift/templates/ring.contents.j2 rename to playbooks/roles/os_swift_sync/templates/ring.contents.j2 index d12ce0b757..835fd0f254 100644 --- a/playbooks/roles/os_swift/templates/ring.contents.j2 +++ b/playbooks/roles/os_swift_sync/templates/ring.contents.j2 @@ -47,7 +47,11 @@ {### Loop through the swift_hosts #} {% for host in groups['swift_hosts'] %} {### Set the default storage_ip #} -{% set def_storage_ip = hostvars[host]['swift_storage_address'] %} +{% 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 the default replication_ip #} {% set def_repl_ip = def_storage_ip %} {% if swift.replication_network is defined %} @@ -76,7 +80,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(def_storage_ip) %} +{% set storage_ip = drive.storage_ip | default(swift_vars.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}) %}